Unify macro error handling, and don't dump stack traces for macro errors.

This commit is contained in:
hns 2008-10-16 13:50:29 +00:00
parent ffff56465f
commit 3af404d39e

View file

@ -634,7 +634,7 @@ public final class Skin {
} }
if ((sandbox != null) && !sandbox.contains(name)) { if ((sandbox != null) && !sandbox.contains(name)) {
throw new RuntimeException("Macro " + name + " not allowed in sandbox"); throw new MacroException("Macro not allowed in sandbox: " + name);
} }
Object handler = null; Object handler = null;
@ -700,7 +700,7 @@ public final class Skin {
buffer.setLength(bufLength); buffer.setLength(bufLength);
} }
} else if (standardParams.verboseFailmode(handler, engine)) { } else if (standardParams.verboseFailmode(handler, engine)) {
throw new UnhandledMacroException(name); throw new MacroException("Unhandled macro: " + name);
} }
} else { } else {
value = engine.getProperty(handler, propName); value = engine.getProperty(handler, propName);
@ -708,7 +708,7 @@ public final class Skin {
return filter(value, cx); return filter(value, cx);
} }
} else if (standardParams.verboseFailmode(handler, engine)) { } else if (standardParams.verboseFailmode(handler, engine)) {
throw new UnhandledMacroException(name); throw new MacroException("Unhandled macro: " + name);
} }
return filter(null, cx); return filter(null, cx);
} }
@ -781,8 +781,8 @@ public final class Skin {
throw concur; throw concur;
} catch (TimeoutException timeout) { } catch (TimeoutException timeout) {
throw timeout; throw timeout;
} catch (UnhandledMacroException unhandled) { } catch (MacroException mx) {
String msg = "Unhandled Macro: " + unhandled.getMessage(); String msg = mx.getMessage();
cx.reval.getResponse().write(" [" + msg + "] "); cx.reval.getResponse().write(" [" + msg + "] ");
app.logError(msg); app.logError(msg);
} catch (Exception x) { } catch (Exception x) {
@ -811,9 +811,9 @@ public final class Skin {
throws Exception { throws Exception {
if (name == null) { if (name == null) {
throw new RuntimeException("Empty macro filter"); throw new MacroException("Empty macro filter");
} else if (sandbox != null && !sandbox.contains(name)) { } else if (sandbox != null && !sandbox.contains(name)) {
throw new RuntimeException("Macro " + name + " not allowed in sandbox"); throw new MacroException("Macro not allowed in sandbox: " + name);
} }
Object handlerObject = null; Object handlerObject = null;
@ -835,7 +835,7 @@ public final class Skin {
return filter(retval, cx); return filter(retval, cx);
} else { } else {
throw new RuntimeException("Undefined Filter " + name); throw new MacroException("Undefined macro filter: " + name);
} }
} }
@ -1121,12 +1121,13 @@ public final class Skin {
} }
/** /**
* Exception type for unhandled macros * Exception type for unhandled, forbidden or failed macros
*/ */
class UnhandledMacroException extends Exception { class MacroException extends Exception {
UnhandledMacroException(String name) { MacroException(String message) {
super(name); super(message);
}
} }
} }
}