Closed zbenj closed 4 months ago
This is to be expected because that's not valid PostgreSQL code.
So you would expect a different kind of exception to be thrown?
So you would expect a different kind of exception to be thrown?
Yes,It's better this way because I don't know if there are any other errors, so I wouldn't know how to differentiate them when using try-catch.
So, instead of getting an instance of Error
you would like to something like an instance of ParseError
to be thrown?
That's a possible change. But it'll have to wait until next major release as it would be a breaking change.
Though I'm really in the same boat as you. I don't know what other kinds of errors might come from the Nearley parser. I'd have to catch this parse error from Nearley and re-throw it as some other type of error. I'm not quite sure whether it would be better to wrap the underlying parser errors or leave them as-is.
I think a simpler approach for you might be to simply check if error.message
starts with text: Parse error
. This way you can catch both parsing errors from sql-formatter itself and from the underlying Nearley parser.
See sqlFormatter.test.ts for an overview of what kind of errors you can expect.
Ok,I got it,Thanks! I have currently processed it in the simple way you mentioned.
Input data
Which SQL and options did you provide as input?
Actual Output
Console Output
Usage