-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
read file needs better error handling for options.
If the filename is supplied without quotes, we give out this bizarre error:
juttle -e "read file -file /tmp/nosuch"
Invalid flags supplied to RegExp constructor 'nosuch'
If the filename is supplied properly but does not exist, then we give the right error, albeit verbose - any chance for shortening this up?
juttle -e "read file -file '/tmp/nosuch'"
Error: internal error Error: ENOENT: no such file or directory, open '/tmp/nosuch' { [RuntimeError: Error: internal error Error: ENOENT: no such file or directory, open '/tmp/nosuch']
message: 'Error: internal error Error: ENOENT: no such file or directory, open \'/tmp/nosuch\'',
code: 'RT-INTERNAL-ERROR',
info:
{ error: 'Error: ENOENT: no such file or directory, open \'/tmp/nosuch\'',
location: { filename: 'main', start: [Object], end: [Object] },
procName: 'read-file' } }
└───────────┴───────────┘
If the input file is not in JSON format, we should say so, rather than complaining about its first character (/tmp/hello here contains HELLO):
juttle -e "read file -file '/tmp/hello'"
Error: internal error SyntaxError: Unexpected token H { [RuntimeError: Error: internal error SyntaxError: Unexpected token H]
message: 'Error: internal error SyntaxError: Unexpected token H',
code: 'RT-INTERNAL-ERROR',
info:
{ error: 'SyntaxError: Unexpected token H',
location: { filename: 'main', start: [Object], end: [Object] },
procName: 'read-file' } }
└───────────┴───────────┘
Additionally, I would welcome a change from read file -file to read file -path, it is clearer and would prevent misspelling / misremembering like read -file file which my fingers keep typing out. The outcome of that is correct, but also not greatly intuitive:
juttle> read -file file '/tmp/foo'
<input>:1:6:
1:read -file file '/tmp/foo'
^
Expected identifier but "-" found. (JUTTLE-SYNTAX-ERROR-WITH-EXPECTED)
Reactions are currently unavailable