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.
Currently, this only works with nashorn
Can pretty print an exception :
Exports eventWrapper : a decorator intended for events (registered via events.*), catching exceptions and pretty printing them to relevant player(s)
Exports functionWrapper : decorator intended for function, catching exceptions and pretty printing them to the function caller
Direct integration with scriptcraft __onCommand : catch all exception generated by /js command, and pretty print (instead of simply displaying the exception message)
Finding the function name
Nashorn doesn't make it easy for us : it doesn't give the methodName for JS code, only the filename + line number. So i can't get the function name with only the stack.
Fortunately, __onCommand uses nashorn load function (see doc), which has a neat feature : you can pass a 'name', which will be displayed in the stack trace. Specifically, it's displayed on the stack frame corresponding to the __onCommand call, which is identified by the 'methodName' beeing ''.
We still need to find the function name, when __onCommand is called. To do this, I've opted for inline comments (like
shout
module), of the form "#f:fnName". The clickable chat module automatically adds them to the command (I recommend using that !).Some example screenshots
Wrapped event
The code is the following :
java exception
Note : this is a regular function, the exception is catched by the direct integration with __onCommand
javascript exception
Note : this is a regular function, the exception is catched by the direct integration with __onCommand
javascript exception (without function name comment)
Note : this is a regular function, the exception is catched by the direct integration with __onCommand
/js command exception