Skip to content

read file has unclear error messages for bad inputs #44

@dmehra

Description

@dmehra

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions