From e011f65e75589a68bc48f338bcddf1359c76c465 Mon Sep 17 00:00:00 2001 From: altrisi Date: Sun, 20 Feb 2022 19:15:54 +0100 Subject: [PATCH] Fix unhandled exceptions when evaluating operators (#1344) --- src/main/java/carpet/script/Fluff.java | 40 ++++++++++++++------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/main/java/carpet/script/Fluff.java b/src/main/java/carpet/script/Fluff.java index ab2e45ba..9fa199bc 100644 --- a/src/main/java/carpet/script/Fluff.java +++ b/src/main/java/carpet/script/Fluff.java @@ -238,14 +238,16 @@ public abstract class Fluff @Override public LazyValue lazyEval(Context cc, Context.Type type, Expression e, Tokenizer.Token t, final LazyValue v1, final LazyValue v2) { - try - { - return (c, type_ignored) -> AbstractOperator.this.eval(v1.evalValue(c, Context.Type.NONE), v2.evalValue(c, Context.Type.NONE)); - } - catch (RuntimeException exc) - { - throw Expression.handleCodeException(cc, exc, e, t); - } + return (c, typeIgnored) -> { + try + { + return AbstractOperator.this.eval(v1.evalValue(c, Context.Type.NONE), v2.evalValue(c, Context.Type.NONE)); + } + catch (RuntimeException exc) + { + throw Expression.handleCodeException(cc, exc, e, t); + } + }; } } @@ -267,24 +269,26 @@ public abstract class Fluff @Override public LazyValue lazyEval(Context cc, Context.Type type, Expression e, Tokenizer.Token t, final LazyValue v1, final LazyValue v2) { - try + if (v2 != null) { - if (v2 != null) + throw new ExpressionException(cc, e, t, "Did not expect a second parameter for unary operator"); + } + return (c, ignoredType) -> { + try { - throw new ExpressionException(cc, e, t, "Did not expect a second parameter for unary operator"); + return AbstractUnaryOperator.this.evalUnary(v1.evalValue(c, Context.Type.NONE)); } - return (c, ignored_type) -> AbstractUnaryOperator.this.evalUnary(v1.evalValue(c, Context.Type.NONE)); - } - catch (RuntimeException exc) - { - throw Expression.handleCodeException(cc, exc, e, t); - } + catch (RuntimeException exc) + { + throw Expression.handleCodeException(cc, exc, e, t); + } + }; } @Override public Value eval(Value v1, Value v2) { - throw new RuntimeException("Shouldn't end up here"); + throw new IllegalStateException("Shouldn't end up here"); } public abstract Value evalUnary(Value v1);