Errors have no line number
demipixel opened this issue ยท 6 comments
Currently you might expect to get an error like this:
[21:27:36 ERROR]: [scriptcraft] javax.script.ScriptException: TypeError: Cannot read property "length" from undefined in <eval> at line number 36 at column number 6
Unfortunately, this does not provide the line number of the error. Is there a way to fix this? I seems to remember there is sometimes a line number, but I don't know exactly when.
The simplest example would be:
events.playerMove(function() {
df
});
where the error is
[17:22:05 ERROR]: Could not pass event PlayerMoveEvent to scriptcraft v3.2.1-2016-12-23
jdk.nashorn.internal.runtime.ECMAException: ReferenceError: "df" is not defined
at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57) ~[nashorn.jar:?]
at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319) ~[nashorn.jar:?]
at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291) ~[nashorn.jar:?]
at jdk.nashorn.internal.objects.Global.__noSuchProperty__(Global.java:1426) ~[nashorn.jar:?]
at jdk.nashorn.internal.scripts.Script$Recompilation$6023$86AA$\^eval\_.L:1$L:2(<eval>:3) ~[?:?]
at jdk.nashorn.internal.scripts.Script$Recompilation$5807$1377AA$\^eval\_.L:1$on$execute(<eval>:61) ~[?:?]
at org.bukkit.plugin.EventExecutor$$NashornJavaAdapter.execute(Unknown Source) ~[?:?]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.11.2.jar:git-Spigot-7d78b81-e2a288c]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.11.2.jar:git-Spigot-7d78b81-e2a288c]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.11.2.jar:git-Spigot-7d78b81-e2a288c]
at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:615) [spigot-1.11.2.jar:git-Spigot-7d78b81-e2a288c]
at net.minecraft.server.v1_11_R1.PacketPlayInFlying.a(SourceFile:126) [spigot-1.11.2.jar:git-Spigot-7d78b81-e2a288c]
at net.minecraft.server.v1_11_R1.PacketPlayInFlying$PacketPlayInPosition.a(SourceFile:57) [spigot-1.11.2.jar:git-Spigot-7d78b81-e2a288c]
at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.11.2.jar:git-Spigot-7d78b81-e2a288c]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_111]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_111]
at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [spigot-1.11.2.jar:git-Spigot-7d78b81-e2a288c]
at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:739) [spigot-1.11.2.jar:git-Spigot-7d78b81-e2a288c]
at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot-1.11.2.jar:git-Spigot-7d78b81-e2a288c]
at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:675) [spigot-1.11.2.jar:git-Spigot-7d78b81-e2a288c]
at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:574) [spigot-1.11.2.jar:git-Spigot-7d78b81-e2a288c]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]
Simplest example of no line number existing. Working on an example for the one I posted (from undefined in <eval>
)
Can you provide a reproducible case where specific code does not return the message you expect? This will help us to see what you're seeing and to determine if the output is correct or if there is a problem.
Are you using Java 1.7 or 1.8? Which version of ScriptCraft?
Thanks for the info. I see what you mean. This is probably information that only the JDK can provide. I'll look into it.
@demipixel - Check out this error line from your copy/paste:
at jdk.nashorn.internal.scripts.Script$Recompilation$6023$86AA$\^eval\.L:1$L:2(<eval>:3) ~[?:?]_
I believe that's telling us that the error occurred on L:2 of 3. Please experiment with that, move bad lines around, and see if that line in the stack consistently points to the error line.
In the next line of the stack we see on$execute at line 61. I believe that's a reference to the line that tried to call your playerMove event:
/src/main/js/lib/events-bukkit.js
61 handler.call( bound, evt, cancel );
I was going to suggest we add a try/catch block around that. In fact, events-canary.js does have error handling around that line but the bukkit version doesn't.
try {
handler.call(bound, e, cancel);
} catch ( error ){
console.log('Error while executing handler:' + handler +
' for event type:' + eventType +
' error: ' + error);
}
If @walterhiggins agrees, I think we should wrap the Bukkit call in an error handler. The Bukkit EventException (error variable) has a getCause() method from which we can get all of the exception info and maybe display relevant information more elegantly. We might even be able to pull the bad line number from the stack trace in there...
Waiting for responses from both of you before looking closer.
Yep, seems like looking further down in the stack will show the line number. Still would be nice to have a line number at the top.
Not to be too literal but since the subject of this issue is "Errors have no line number" and we've found that there is a line number, I'm going to close this one item.
Now, as to having a line number further up, that's a separate enhancement request which will have its own life cycle and I'm hoping @demipixel will create it.
As to my notes about error handling, that's yet another topic for which I'll create another ticket soon.