From 768ff9387c10ce7cd6607b710c2e3874907d845b Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 22 Jan 2011 16:23:04 -0800 Subject: [PATCH] Improved scripting error messages. --- src/com/sk89q/worldedit/WorldEditController.java | 4 +++- .../worldedit/scripting/RhinoCraftScriptEngine.java | 10 +++++++++- .../worldedit/scripting/SunRhinoCraftScriptEngine.java | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/com/sk89q/worldedit/WorldEditController.java b/src/com/sk89q/worldedit/WorldEditController.java index 7e2355248..daed36d1d 100644 --- a/src/com/sk89q/worldedit/WorldEditController.java +++ b/src/com/sk89q/worldedit/WorldEditController.java @@ -2203,13 +2203,15 @@ public class WorldEditController { } catch (ScriptException e) { player.printError("Failed to execute:");; player.printRaw(e.getMessage()); + e.printStackTrace(); } catch (NumberFormatException e) { throw e; } catch (WorldEditException e) { throw e; } catch (Throwable e) { - player.printError("Failed to execute (exception):"); + player.printError("Failed to execute (see console):"); player.printRaw(e.getClass().getCanonicalName()); + e.printStackTrace(); } finally { for (EditSession editSession : scriptContext.getEditSessions()) { session.remember(editSession); diff --git a/src/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java b/src/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java index c872b4874..c6aac2743 100644 --- a/src/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java +++ b/src/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java @@ -22,6 +22,7 @@ package com.sk89q.worldedit.scripting; import java.util.Map; import javax.script.ScriptException; import org.mozilla.javascript.*; +import com.sk89q.worldedit.WorldEditException; public class RhinoCraftScriptEngine implements CraftScriptEngine { private int timeLimit; @@ -38,7 +39,7 @@ public class RhinoCraftScriptEngine implements CraftScriptEngine { @Override public Object evaluate(String script, String filename, Map args) - throws ScriptException { + throws ScriptException, Throwable { RhinoContextFactory factory = new RhinoContextFactory(timeLimit); Context cx = factory.enterContext(); ScriptableObject scriptable = new ImporterTopLevel(cx); @@ -53,6 +54,13 @@ public class RhinoCraftScriptEngine implements CraftScriptEngine { } catch (Error e) { throw new ScriptException(e.getMessage()); } catch (RhinoException e) { + if (e instanceof WrappedException) { + Throwable cause = ((WrappedException)e).getCause(); + if (cause instanceof WorldEditException) { + throw ((WrappedException)e).getCause(); + } + } + String msg; int line = (line = e.lineNumber()) == 0 ? -1 : line; diff --git a/src/com/sk89q/worldedit/scripting/SunRhinoCraftScriptEngine.java b/src/com/sk89q/worldedit/scripting/SunRhinoCraftScriptEngine.java index 6f7e1dfb4..825096215 100644 --- a/src/com/sk89q/worldedit/scripting/SunRhinoCraftScriptEngine.java +++ b/src/com/sk89q/worldedit/scripting/SunRhinoCraftScriptEngine.java @@ -22,6 +22,7 @@ package com.sk89q.worldedit.scripting; import java.util.Map; import javax.script.ScriptException; import com.sk89q.worldedit.WorldEditController; +import com.sk89q.worldedit.WorldEditException; import sun.org.mozilla.javascript.internal.*; public class SunRhinoCraftScriptEngine implements CraftScriptEngine { @@ -63,7 +64,10 @@ public class SunRhinoCraftScriptEngine implements CraftScriptEngine { throw new ScriptException(e.getMessage()); } catch (RhinoException e) { if (e instanceof WrappedException) { - throw ((WrappedException)e).getCause(); + Throwable cause = ((WrappedException)e).getCause(); + if (cause instanceof WorldEditException) { + throw ((WrappedException)e).getCause(); + } } String msg;