# Buggy code
def check_var(name):
    tv = self.typevars[name]
    if not tv.defined:
        offender = find_offender(name)
        val = getattr(offender, "value", "unknown operation")
        loc = getattr(offender, "loc", "unknown location")
        msg = "Undefined variable '%s', operation: %s, location: %s"
        raise TypingError(msg % (var, val, loc), loc)
    tp = tv.getone()
    if not tp.is_precise():
        offender = find_offender(name, exhaustive=True)
        msg = "Cannot infer the type of variable '%s'%s, have imprecise type: %s. %s"
        istmp = " (temporary variable)" if var.startswith("$") else ""
        loc = getattr(offender, "loc", "unknown location")
        # is this an untyped list? try and provide help
        extra_msg = diagnose_imprecision(offender)
        raise TypingError(msg % (var, istmp, tp, extra_msg), loc)
    else:  # type is precise, hold it
        typdict[var] = tp


# Traceback (AttributeError)
Traceback (most recent call last):
File "examples/hello.py", line 25, in <module>
main()
File "examples/hello.py", line 19, in main
print(hpat(2))
File "numba/numba/dispatcher.py", line 367, in _compile_for_args
raise e
File "numba/numba/dispatcher.py", line 324, in _compile_for_args
return self.compile(tuple(argtypes))
File "numba/numba/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "numba/numba/dispatcher.py", line 655, in compile
cres = self._compiler.compile(args, return_type)
File "numba/numba/dispatcher.py", line 82, in compile
pipeline_class=self.pipeline_class)
File "numba/numba/compiler.py", line 905, in compile_extra
return pipeline.compile_extra(func)
File "numba/numba/compiler.py", line 367, in compile_extra
return self._compile_bytecode()
File "numba/numba/compiler.py", line 836, in _compile_bytecode
return self._compile_core()
File "numba/numba/compiler.py", line 823, in _compile_core
res = pm.run(self.status)
File "numba/numba/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "numba/numba/compiler.py", line 253, in run
raise patched_exception
File "numba/numba/compiler.py", line 244, in run
stage()
File "numba/numba/compiler.py", line 478, in stage_nopython_frontend
self.locals)
File "numba/numba/compiler.py", line 1009, in type_inference_stage
typemap, restype, calltypes = infer.unify()
File "numba/numba/typeinfer.py", line 924, in unify
check_var(var)
File "numba/numba/typeinfer.py", line 910, in check_var
raise TypingError(msg % (var, val, loc), loc)
File "numba/numba/errors.py", line 406, in __init__
highlight("%s\n%s\n" % (msg, loc.strformat())))
AttributeError: Failed in hpat mode pipeline (step: nopython frontend)
'str' object has no attribute 'strformat'

# Fixed code
def check_var(name):
    tv = self.typevars[name]
    if not tv.defined:
        offender = find_offender(name)
        val = getattr(offender, "value", "unknown operation")
        loc = getattr(offender, "loc", ir.unknown_loc)
        msg = "Undefined variable '%s', operation: %s, location: %s"
        raise TypingError(msg % (var, val, loc), loc)
    tp = tv.getone()
    if not tp.is_precise():
        offender = find_offender(name, exhaustive=True)
        msg = "Cannot infer the type of variable '%s'%s, have imprecise type: %s. %s"
        istmp = " (temporary variable)" if var.startswith("$") else ""
        loc = getattr(offender, "loc", ir.unknown_loc)
        # is this an untyped list? try and provide help
        extra_msg = diagnose_imprecision(offender)
        raise TypingError(msg % (var, istmp, tp, extra_msg), loc)
    else:  # type is precise, hold it
        typdict[var] = tp