You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
read file has unclear error messages for bad inputs #44
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):
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:
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.
The “bizarre error” with unquoted file name. This is caused by:
/tmp/nosuch being considered a regexp literal.
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.
The ugly ENOENT error. This is just missing error handling in the file backend.
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.
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.
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?
Activity
demmer commentedon Jan 4, 2016
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:
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
-fileto-pathare totally valid and should be fixed.dmajda commentedon Jan 6, 2016
This is a multitude of mostly unrelated issues:
The “bizarre error” with unquoted file name. This is caused by:
/tmp/nosuchbeing considered a regexp literal.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/nosucha 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.The ugly ENOENT error. This is just missing error handling in the
filebackend.The unhelpful syntax error. This is just missing error handling in the
filebackend. Note this bug may also exist in other places where we parse formatted input.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.Change
-pathto-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?
Merge pull request #44 from juttle/move-tests