replace ScriptException with a better one#18600
Merged
rmuir merged 2 commits intoelastic:masterfrom May 26, 2016
Merged
Conversation
18 tasks
| writer.writeDebugInfo(offset); | ||
| } | ||
|
|
||
| if (cat) { |
Contributor
There was a problem hiding this comment.
Is there a reason these two aren't combined?
Contributor
Author
There was a problem hiding this comment.
this node has more if (cat) cases beneath and is kinda complex. I think maybe too complex for bytecode manipulation in a single node? Or at least it needs some assistance. If it gets refactored, i didnt want the debug info to go away with it on accident...
Contributor
|
LGTM. Thanks for making these changes, exceptions just got a whole lot better 👍 ! Left one minor comment. |
| template.getScript(), scriptLang); | ||
| } | ||
| } catch (Exception e) { | ||
| // TODO: remove this when all script engines have good exceptions! |
Contributor
There was a problem hiding this comment.
nit pick why not:
} catch (ScriptException e) {
throw e;// its already good!
} catch (Exception e) {
...
Contributor
|
Looked through the exception related changes and LGTM. I left a nitpick :) this is a fantastic improvement! thanks for doing this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Exceptions from scripts are not handled well today:
The current situation just encourages even more bad exception handling. People complain if you get NullPointerException when you dereference a null pointer, but that is exactly what you deserve if you do this! And it tells you all you need to figure it out: its right there in the stacktrace with line numbers!
We should just "box" the exception a single time, with all the stuff you need to figure out the problem by default. That means telling you what script hit the problem, what language it was in, a "simple" reason of what happened, and a relevant "stacktrace" to the script. The original root cause is always preserved, if someone asks for the stacktrace or looks at the logs, they will see all that really happened, this is more about the horror of whats happening today at the REST layer.
In order to contend with "everything shoved on a single line", we have to do some highlighting. Normally, line numbers and existing lines work great for code, but since we don't have those, we have to work with what we've got.
For painless that means, encoding offsets as line numbers into the bytecode, wherever an exception can strike. It also means breaking down the (probably massive) script into sentences that have enough meaningful context: we use leaf S* nodes as "sentences".
For expressions it means when a "variable" goes wrong (e.g. not in mappings), we just highlight what went wrong with that variable definition, etc.
Other scripting engines can be adapted to use this, e.g. you can get some of this kind of info from at least some groovy/javascript/python exceptions. For now, they still keep using the deprecated "GeneralScriptException" and do the same as before. If someone else wants to improve them, great.
Here are some example runtime errors:
It helps also for compile-time errors (and the "link time" of expressions where it binds against the mappings):