refactor: Alter handling of errors in bindings (#1395)

* Alter handling of errors in bindings
 - Fixes #1384

* Arbitrarily use TextComponent#of for InputParseException
Dieser Commit ist enthalten in:
Jordan 2021-11-11 17:37:25 +00:00 committet von GitHub
Ursprung 806ea14ad2
Commit 6df16cfe96
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 59 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -101,11 +101,15 @@ public class Bindings {
@Override
public ConversionResult<Object> convert(String s, InjectedValueAccess access) {
try {
Object o = invoke(s, argsFunc, access, method);
if (o == null) {
return FailedConversion.from(new NullPointerException());
}
return SuccessfulConversion.fromSingle(o);
} catch (Throwable t) {
return FailedConversion.from(t);
}
}
});
}

Datei anzeigen

@ -27,6 +27,7 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import org.enginehub.piston.exception.StopExecutionException;
import org.enginehub.piston.inject.InjectedValueAccess;
import java.util.UUID;
@ -49,36 +50,76 @@ public class ConsumeBindings extends Bindings {
@Binding
@Confirm(Confirm.Processor.REGION)
public int regionMultiple(Actor actor, InjectedValueAccess context, @Selection Region region, String argument) {
try {
int times = (int) Expression.compile(argument).evaluate();
return Confirm.Processor.REGION.check(actor, context, times);
} catch (Throwable t) {
if (t instanceof StopExecutionException) { // Maintain throw from Confirm#check
throw t;
} else {
throw new InputParseException(TextComponent.of(t.getMessage()), t);
}
}
}
@Binding
@Confirm(Confirm.Processor.RADIUS)
public Integer radiusInteger(Actor actor, InjectedValueAccess context, String argument) {
try {
int times = (int) Expression.compile(argument).evaluate();
return Confirm.Processor.RADIUS.check(actor, context, times);
} catch (Throwable t) {
if (t instanceof StopExecutionException) { // Maintain throw from Confirm#check
throw t;
} else {
throw new InputParseException(TextComponent.of(t.getMessage()), t);
}
}
}
@Binding
@Confirm(Confirm.Processor.LIMIT)
public Integer limitInteger(Actor actor, InjectedValueAccess context, String argument) {
try {
int times = (int) Expression.compile(argument).evaluate();
return Confirm.Processor.LIMIT.check(actor, context, times);
} catch (Throwable t) {
if (t instanceof StopExecutionException) { // Maintain throw from Confirm#check
throw t;
} else {
throw new InputParseException(TextComponent.of(t.getMessage()), t);
}
}
}
@Binding
@Confirm(Confirm.Processor.RADIUS)
public Double radiusDouble(Actor actor, InjectedValueAccess context, String argument) {
try {
double times = Expression.compile(argument).evaluate();
return Confirm.Processor.RADIUS.check(actor, context, times);
} catch (Throwable t) {
if (t instanceof StopExecutionException) { // Maintain throw from Confirm#check
throw t;
} else {
throw new InputParseException(TextComponent.of(t.getMessage()), t);
}
}
}
@Binding
@Confirm(Confirm.Processor.LIMIT)
public Double limitDouble(Actor actor, InjectedValueAccess context, String argument) {
try {
double times = Expression.compile(argument).evaluate();
return Confirm.Processor.LIMIT.check(actor, context, times);
} catch (Throwable t) {
if (t instanceof StopExecutionException) { // Maintain throw from Confirm#check
throw t;
} else {
throw new InputParseException(TextComponent.of(t.getMessage()), t);
}
}
}
@Binding