diff options
author | Adam J. Stewart <ajstewart426@gmail.com> | 2018-06-02 22:53:18 -0500 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2018-06-02 20:53:18 -0700 |
commit | 9862c97d386bf9d886efa0c192b09be309299dde (patch) | |
tree | ec7d06c702d68b95dcc4e5053afe8a21cc09f585 /lib | |
parent | ff56d739a03886ee3d49df2ed8b9f1c605bba61e (diff) | |
download | spack-9862c97d386bf9d886efa0c192b09be309299dde.tar.gz spack-9862c97d386bf9d886efa0c192b09be309299dde.tar.bz2 spack-9862c97d386bf9d886efa0c192b09be309299dde.tar.xz spack-9862c97d386bf9d886efa0c192b09be309299dde.zip |
Fix package error message line numbers (#8271)
Line numbers were reported as zero-indexed, but we need to adjust.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/build_environment.py | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py index c2d91902a4..59af563c92 100644 --- a/lib/spack/spack/build_environment.py +++ b/lib/spack/spack/build_environment.py @@ -775,23 +775,31 @@ def get_package_context(traceback, context=3): if isinstance(obj, spack.package.PackageBase): break - # we found obj, the Package implementation we care about. - # point out the location in the install method where we failed. - lines = [] - lines.append("%s:%d, in %s:" % ( - inspect.getfile(frame.f_code), frame.f_lineno, frame.f_code.co_name - )) + # We found obj, the Package implementation we care about. + # Point out the location in the install method where we failed. + lines = [ + '{0}:{1:d}, in {2}:'.format( + inspect.getfile(frame.f_code), + frame.f_lineno - 1, # subtract 1 because f_lineno is 0-indexed + frame.f_code.co_name + ) + ] # Build a message showing context in the install method. sourcelines, start = inspect.getsourcelines(frame) - fl = frame.f_lineno - start - start_ctx = max(0, fl - context) - sourcelines = sourcelines[start_ctx:fl + context + 1] + # Calculate lineno of the error relative to the start of the function. + # Subtract 1 because f_lineno is 0-indexed. + fun_lineno = frame.f_lineno - start - 1 + start_ctx = max(0, fun_lineno - context) + sourcelines = sourcelines[start_ctx:fun_lineno + context + 1] + for i, line in enumerate(sourcelines): - is_error = start_ctx + i == fl - mark = ">> " if is_error else " " - marked = " %s%-6d%s" % (mark, start_ctx + i, line.rstrip()) + is_error = start_ctx + i == fun_lineno + mark = '>> ' if is_error else ' ' + # Add start to get lineno relative to start of file, not function. + marked = ' {0}{1:-6d}{2}'.format( + mark, start + start_ctx + i, line.rstrip()) if is_error: marked = colorize('@R{%s}' % marked) lines.append(marked) |