Fix tracebacks when prefix not specified.

This fixes #6886 by accounting for instances where the prefix is not
specified, catching the KeyError exceptions.