Permalink
Browse files

Fix unhandled exception in 'source' when there's a syntax error.

The spec tests shows that shells disagree on the exit code, and that
dash is more strict.
  • Loading branch information...
Andy Chu
Andy Chu committed Sep 1, 2018
1 parent 1f9d6f6 commit 517ec2b8fb1cf1aef578cdf6b6c2cb3e5f6a2f0f
Showing with 16 additions and 8 deletions.
  1. +5 −8 core/cmd_exec.py
  2. +11 −0 spec/builtin-eval-source.test.sh
View
@@ -182,15 +182,12 @@ def _Complete(self, argv):
def _EvalHelper(self, c_parser, source_name):
self.arena.PushSource(source_name)
try:
node = c_parser.ParseWholeFile()
# NOTE: We could model a parse error as an exception, like Python, so we
# get a traceback. (This won't be applicable for a static module
# system.)
if not node:
try:
node = c_parser.ParseWholeFile()
except util.ParseError as e:
util.error('Parse error in %r:', source_name)
err = c_parser.Error()
ui.PrintErrorStack(err, self.arena, sys.stderr)
return 1
ui.PrettyPrintError(e, self.arena, sys.stderr)
return 2
status = self._Execute(node)
return status
@@ -57,3 +57,14 @@ func
foo=foo_val
foo=
## END
#### Source with syntax error
# TODO: We should probably use dash behavior of a fatal error.
echo 'echo >' > $TMP/syntax-error.sh
. $TMP/syntax-error.sh
echo status=$?
## stdout: status=2
## OK bash/mksh stdout: status=1
## OK zsh stdout: status=126
## OK dash stdout-json: ""
## OK dash status: 2

0 comments on commit 517ec2b

Please sign in to comment.