Skip to content

Commit

Permalink
[errors] Better message when attempting to stringify a List (#1764)
Browse files Browse the repository at this point in the history
  • Loading branch information
Melkor333 authored Jan 30, 2024
1 parent aa02881 commit d49876e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion osh/word_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,9 @@ def _ValueToPartValue(val, quoted, part_loc):
return part_value.Array(val.d.values())

# Cases added for YSH
# value_e.List is also here - we use val_ops.stringify()s err message
elif case(value_e.Null, value_e.Bool, value_e.Int, value_e.Float,
value_e.Eggex):
value_e.Eggex, value_e.List):
s = val_ops.Stringify(val, loc.Missing)
return part_value.String(s, quoted, not quoted)

Expand Down
5 changes: 5 additions & 0 deletions ysh/val_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ def Stringify(val, blame_loc, prefix=''):
val = cast(value.Eggex, UP_val)
s = regex_translate.AsPosixEre(val) # lazily converts to ERE

elif case(value_e.List):
raise error.TypeErrVerbose(
"%sgot a List, which can't be stringified. Perhaps use @ instead of $, or use join()" % prefix,
blame_loc)

else:
raise error.TypeErr(
val, "%sexpected Null, Bool, Int, Float, Eggex" % prefix,
Expand Down

0 comments on commit d49876e

Please sign in to comment.