Permalink
Browse files

Change an error case in cmd_parse.py to throw exceptions.

Catch exception when parsing 'trap' code.

Addresses issues #27 and #103.
  • Loading branch information...
Andy Chu
Andy Chu committed Aug 22, 2018
1 parent a2e037b commit 62017dc61c67ae7949cbb5ca96720b2d89bf349e
Showing with 15 additions and 6 deletions.
  1. +13 −3 core/cmd_exec.py
  2. +2 −3 osh/cmd_parse.py
View
@@ -219,13 +219,23 @@ def ParseTrapCode(self, code_str):
source_name = '<trap string>'
self.arena.PushSource(source_name)
try:
node = c_parser.ParseWholeFile()
if not node:
# TODO: Get rid of duplicate error handling:
err = None
try:
node = c_parser.ParseWholeFile()
except util.ParseError as e:
err = e
else:
if not node:
err = c_parser.Error()
if err:
util.error('Parse error in %r:', source_name)
err = c_parser.Error()
ui.PrintErrorStack(err, self.arena, sys.stderr)
return None
finally:
self.arena.PopSource()
View
@@ -21,6 +21,7 @@
from osh.bool_parse import BoolParser
log = util.log
p_die = util.p_die
command_e = ast.command_e
word_e = ast.word_e
assign_op_e = ast.assign_op_e
@@ -267,9 +268,7 @@ def ParseRedirect(self):
if not self._Peek(): return None
if self.c_kind != Kind.Word:
self.AddErrorContext(
'Expected word after redirect operator', word=self.cur_word)
return None
p_die('Invalid token after redirect operator', word=self.cur_word)
new_word = word.TildeDetect(self.cur_word)
node.arg_word = new_word or self.cur_word

0 comments on commit 62017dc

Please sign in to comment.