Skip to content

read file has unclear error messages for bad inputs #44

Open

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)

Activity

  1. demmer commented on Jan 4, 2016

    @demmer
    Contributor

    The first issue you mentioned has nothing to do with the file adapter per se. If you don't properly quote a file path, the grammar will try to interpret it in confusing ways:

    juttle> emit | put x = /foo/bar
    Invalid flags supplied to RegExp constructor 'bar'
    Unhandled rejection SyntaxError: Invalid flags supplied to RegExp constructor 'bar'
        at new RegExp (native)
        at main_1 (eval at <anonymous> (/Users/demmer/node_modules/juttle/lib/compiler/index.js:32:23), <anonymous>:24:112)
        at eval (eval at <anonymous> (/Users/demmer/node_modules/juttle/lib/compiler/index.js:32:23), <anonymous>:33:75)
        at stages.flowgraph (/Users/demmer/node_modules/juttle/lib/compiler/index.js:34:9)
        at /Users/demmer/node_modules/juttle/lib/compiler/index.js:91:20
        at tryCatcher (/Users/demmer/node_modules/juttle/node_modules/bluebird/js/main/util.js:26:23)
        at Promise._settlePromiseFromHandler (/Users/demmer/node_modules/juttle/node_modules/bluebird/js/main/promise.js:507:31)
        at Promise._settlePromiseAt (/Users/demmer/node_modules/juttle/node_modules/bluebird/js/main/promise.js:581:18)
        at Promise._settlePromises (/Users/demmer/node_modules/juttle/node_modules/bluebird/js/main/promise.js:697:14)
        at Async._drainQueue (/Users/demmer/node_modules/juttle/node_modules/bluebird/js/main/async.js:123:16)
        at Async._drainQueues (/Users/demmer/node_modules/juttle/node_modules/bluebird/js/main/async.js:133:10)
        at Immediate.Async.drainQueues [as _onImmediate] (/Users/demmer/node_modules/juttle/node_modules/bluebird/js/main/async.js:15:14)
        at processImmediate [as _immediateCallback] (timers.js:383:17)
    juttle> emit | put x = /foo/bar.juttle
    <input>:1:16:
       1:emit | put x = /foo/bar.juttle
                        ^^^^^^^^^^^^^^^
    Error: variable 'juttle' is not exported by module  code (RT-NOT-EXPORTED)
    

    Obviously in the case of the file adapter you're more likely to fall into this problem, but I don't know what we could do about this. @dmajda do you have any bright ideas?

    The other three comments including the suggestion to rename -file to -path are totally valid and should be fixed.

  2. dmajda commented on Jan 6, 2016

    @dmajda
    Contributor

    This is a multitude of mostly unrelated issues:

    1. The “bizarre error” with unquoted file name. This is caused by:

      1. /tmp/nosuch being considered a regexp literal.
      2. Not validating regexp flags in the parser, but passing them through to JavaScript, which blows up with its own error.

      I don’t think it makes sense to make the parsing more strict (I just checked and at least JavaScript, Ruby, and Perl also consider /tmp/nosuch a regexp literal) but we can definitely do our own check on the flags with a better error message. The fact that we don’t do that is a clear bug.

    2. The ugly ENOENT error. This is just missing error handling in the file backend.

    3. The unhelpful syntax error. This is just missing error handling in the file backend. Note this bug may also exist in other places where we parse formatted input.

    4. Unintuitive error message in case of read -file file '/tmp/foo'. I think with a simple grammar change we can have a message like “Expected adapter name but "-" found.”, which is much more instructive.

    5. Change -path to -file. Both variants are fine with me, so not opposing to the change.

    @dmehra Could you please file a separate issue for each of these?

  3. added a commit that references this issue on Jan 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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