spyql
spyql copied to clipboard
improve error messaging when I'm holding it wrong
This is probably related-ish to #83.
I saw a note about this, thought "hey what a cool tool", tried to write things that would use spyql to read json. Consistently got page-long stack backtraces showing various errors from uncaught exceptions, usually coming down to:
[...]
File "/Users/seebs/py3/lib/python3.11/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1 (char 2)
This is a very confusing error.
The actual problem: My input was the result of using jq
on something, so it looked like ```
{
"id": 0,
"x": "foo"
}
What I wanted was the result of using `jq -c` on something, which would have looked like ```
{"id": 0, "x": "foo"}```
I don't dispute that I'm holding it wrong, but it feels to me like it would potentially be practical to check for the json decode error, and report something more useful rather than the stack backtrace. And, in particular, perhaps to point out "inputs are expected to be self-contained JSON objects on each line, not multiline pretty-printed constructs".
Hey. You are totally right, regarding the stack trace. This behavior happens in parts of the code where there is no error handling, which seems to be the case for JSON reading/decoding.
And yes, regarding JSON input, SPyQL only supports JSON lines, which means one input line should be a complete JSON object. If you are piping from jq, you can simply add the -c option to the jq command (I do it all the time).
Thank you so much for your feedback! I will look into the issue and try to improve this behavior.