Improve exceptions (#1256)

- Kick more exceptions further up the pipeline to be more likely to be shown to player
- Try to avoid lots of console spamming when it's the same error multiple times
- Allow parsing of FaweExceptions during commands to better give information to players
This commit is contained in:
dordsor21
2021-09-01 15:36:03 +01:00
committed by GitHub
parent 0c9270dbc1
commit fb7e95c440
19 changed files with 415 additions and 231 deletions

View File

@ -5,7 +5,7 @@ import com.fastasyncworldedit.core.configuration.Caption;
public class FaweBlockBagException extends FaweException {
public FaweBlockBagException() {
super(Caption.of("fawe.error.worldedit.some.fails.blockbag"));
super(Caption.of("fawe.error.worldedit.some.fails.blockbag"), Type.BLOCK_BAG);
}
}

View File

@ -1,11 +0,0 @@
package com.fastasyncworldedit.core.internal.exception;
import com.fastasyncworldedit.core.configuration.Caption;
public class FaweChunkLoadException extends FaweException {
public FaweChunkLoadException() {
super(Caption.of("fawe.cancel.worldedit.failed.load.chunk"));
}
}

View File

@ -13,13 +13,28 @@ public class FaweException extends RuntimeException {
public static final FaweException _disableQueue = new FaweException("disableQueue");
private final Component message;
private final Type type;
/**
* New instance. Defaults to {@link FaweException.Type#OTHER}.
*/
public FaweException(String reason) {
this(TextComponent.of(reason));
}
/**
* New instance. Defaults to {@link FaweException.Type#OTHER}.
*/
public FaweException(Component reason) {
this(reason, Type.OTHER);
}
/**
* New instance of a given {@link FaweException.Type}
*/
public FaweException(Component reason, Type type) {
this.message = reason;
this.type = type;
}
@Override
@ -31,6 +46,14 @@ public class FaweException extends RuntimeException {
return message;
}
/**
* Get the {@link FaweException.Type}
* @return the {@link FaweException.Type}
*/
public Type getType() {
return type;
}
public static FaweException get(Throwable e) {
if (e instanceof FaweException) {
return (FaweException) e;
@ -52,4 +75,19 @@ public class FaweException extends RuntimeException {
return this;
}
public enum Type {
MANUAL,
NO_REGION,
OUTSIDE_REGION,
MAX_CHECKS,
MAX_CHANGES,
LOW_MEMORY,
MAX_ENTITIES,
MAX_TILES,
MAX_ITERATIONS,
BLOCK_BAG,
CHUNK,
OTHER
}
}