Skip to content

Commit

Permalink
[refactor] Type-driven refactoring: remove span_id in PrefixPrint()
Browse files Browse the repository at this point in the history
The same can be done for Print_() and PrintMessage(), which now take a
span_id, but should take a location.
  • Loading branch information
Andy C committed Feb 6, 2023
1 parent 2c9231f commit 125ed7a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def RunBuiltin(self, builtin_id, cmd_val):
if e.span_id == runtime.NO_SPID:
e.span_id = self.errfmt.CurrentLocation()
# e.g. 'type' doesn't accept flag '-x'
self.errfmt.PrefixPrint(e.msg, prefix='%r ' % arg0, span_id=e.span_id)
self.errfmt.PrefixPrint(e.msg, '%r ' % arg0, loc.Span(e.span_id))
status = 2 # consistent error code for usage error

return status
Expand Down
7 changes: 4 additions & 3 deletions core/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from _devbuild.gen.id_kind_asdl import Id, Id_t, Id_str
from _devbuild.gen.syntax_asdl import (
Token, SourceLine, command_t, command_str,
loc_t, Token, SourceLine, command_t, command_str,
source_e, source__Stdin, source__MainFile, source__SourcedFile,
source__Alias, source__Reparsed, source__Variable, source__VarRef,
source__ArgvWord, source__Synthetic
Expand Down Expand Up @@ -304,9 +304,10 @@ def CurrentLocation(self):
else:
return runtime.NO_SPID

def PrefixPrint(self, msg, prefix, span_id=runtime.NO_SPID):
# type: (str, str, int) -> None
def PrefixPrint(self, msg, prefix, blame_loc):
# type: (str, str, loc_t) -> None
"""Print a hard-coded message with a prefix, and quote code."""
span_id = location.GetSpanId(blame_loc)
_PrintWithSpanId(prefix, msg, span_id, self.arena, show_code=True)

def Print_(self, msg, span_id=runtime.NO_SPID):
Expand Down
4 changes: 2 additions & 2 deletions osh/cmd_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def _RunAssignBuiltin(self, cmd_val):
arg0 = cmd_val.argv[0]
if e.span_id == runtime.NO_SPID: # fill in default location.
e.span_id = self.errfmt.CurrentLocation()
self.errfmt.PrefixPrint(e.msg, prefix='%r ' % arg0, span_id=e.span_id)
self.errfmt.PrefixPrint(e.msg, '%r ' % arg0, loc.Span(e.span_id))
status = 2 # consistent error code for usage error

return status
Expand Down Expand Up @@ -1046,7 +1046,7 @@ def _Dispatch(self, node, cmd_st):
else:
# Only print warnings, never fatal.
# Bash oddly only exits 1 for 'return', but no other shell does.
self.errfmt.PrefixPrint(msg, prefix='warning: ', span_id=tok.span_id)
self.errfmt.PrefixPrint(msg, 'warning: ', tok)
status = 0

# Note CommandList and DoGroup have no redirects, but BraceGroup does.
Expand Down
2 changes: 0 additions & 2 deletions soil/worker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,6 @@ job-main() {

log-context 'job-main'
mkdir -v -p $out_dir

set -x
ls -l -d $out_dir

disable-git-errors
Expand Down

0 comments on commit 125ed7a

Please sign in to comment.