Skip to content

Commit

Permalink
[osh fix] Fix [[ x =~ $pat ]] error message
Browse files Browse the repository at this point in the history
After changing YSH ~ in previous commit
  • Loading branch information
Andy C committed Dec 16, 2023
1 parent b8075f9 commit 992e145
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
6 changes: 2 additions & 4 deletions osh/sh_expr_eval.py
Expand Up @@ -1071,12 +1071,10 @@ def EvalB(self, node):

try:
indices = libc.regex_search(s2, regex_flags, s1)
except RuntimeError as e:
except ValueError as e:
# Status 2 indicates a regex parse error. This is fatal in OSH but
# not in bash, which treats [[ like a command with an exit code.
msg = e.message # type: str
e_die_status(2, 'Invalid regex %r: %s' % (s2, msg),
loc.Word(node.right))
e_die_status(2, e.message, loc.Word(node.right))

if indices is not None:
self.mem.SetRegexIndices(s1, indices)
Expand Down
3 changes: 1 addition & 2 deletions ysh/expr_eval.py
Expand Up @@ -752,8 +752,7 @@ def _EvalCompare(self, node):
else:
raise AssertionError(op)
except ValueError as e:
# Status 2 indicates a regex parse error. This is fatal in OSH but
# not in bash, which treats [[ like a command with an exit code.
# Status 2 indicates a regex parse error, as with [[ in OSH
e_die_status(2, e.message, op)

if not result:
Expand Down

0 comments on commit 992e145

Please sign in to comment.