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

@ -193,7 +193,7 @@ public class ClipboardCommands {
.getZ() + 1));
FaweLimit limit = actor.getLimit();
if (volume >= limit.MAX_CHECKS) {
throw new FaweException(Caption.of("fawe.cancel.worldedit.cancel.reason.max.checks"));
throw FaweCache.MAX_CHECKS;
}
session.setClipboard(null);
ReadOnlyClipboard lazyClipboard = ReadOnlyClipboard.of(region, !skipEntities, copyBiomes);
@ -558,7 +558,7 @@ public class ClipboardCommands {
PasteEvent event = new PasteEvent(player, clipboard, uri, editSession, to);
WorldEdit.getInstance().getEventBus().post(event);
if (event.isCancelled()) {
throw new FaweException(Caption.of("fawe.cancel.worldedit.cancel.reason.manual"));
throw FaweCache.MANUAL;
}
}
//FAWE end

View File

@ -601,18 +601,13 @@ public class GenerationCommands {
int[] count = new int[1];
final BufferedImage finalImage = image;
RegionVisitor visitor = new RegionVisitor(region, pos -> {
try {
int x = pos.getBlockX() - pos1.getBlockX();
int z = pos.getBlockZ() - pos1.getBlockZ();
int color = finalImage.getRGB(x, z);
BlockType block = tu.getNearestBlock(color);
count[0]++;
if (block != null) {
return editSession.setBlock(pos, block.getDefaultState());
}
return false;
} catch (Throwable e) {
e.printStackTrace();
int x = pos.getBlockX() - pos1.getBlockX();
int z = pos.getBlockZ() - pos1.getBlockZ();
int color = finalImage.getRGB(x, z);
BlockType block = tu.getNearestBlock(color);
count[0]++;
if (block != null) {
return editSession.setBlock(pos, block.getDefaultState());
}
return false;
}, editSession);

View File

@ -774,19 +774,18 @@ public final class PlatformCommandManager {
}
actor.printError(e.getRichMessage());
} catch (CommandExecutionException e) {
handleUnknownException(actor, e.getCause());
} catch (CommandException e) {
if (e.getCause() instanceof FaweException) {
actor.print(Caption.of("fawe.cancel.worldedit.cancel.reason", ((FaweException) e.getCause()).getComponent()));
} else {
handleUnknownException(actor, e.getCause());
}
} catch (CommandException e) {
Component msg = e.getRichMessage();
if (msg != TextComponent.empty()) {
actor.print(TextComponent.builder("")
.append(e.getRichMessage())
.build());
List<String> argList = parseArgs(event.getArguments()).map(Substring::getSubstring).collect(Collectors.toList());
printUsage(actor, argList);
Component msg = e.getRichMessage();
if (msg != TextComponent.empty()) {
List<String> argList = parseArgs(event.getArguments())
.map(Substring::getSubstring)
.collect(Collectors.toList());
printUsage(actor, argList);
}
}
} catch (Throwable t) {
handleUnknownException(actor, t);

View File

@ -273,10 +273,9 @@ public interface Clipboard extends Extent, Iterable<BlockVector3>, Closeable {
}
try {
Operations.completeLegacy(copy);
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
} finally {
editSession.close(); // Make sure editsession is always closed
}
editSession.flushQueue();
return editSession;
}

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.internal.command.exception;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.internal.exception.FaweException;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.DisallowedItemException;
import com.sk89q.worldedit.EmptyClipboardException;
@ -197,4 +198,11 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper {
throw e;
}
//FAWE start
@ExceptionMatch
public void convert(FaweException e) throws CommandException {
throw newCommandException(e.getComponent(), e);
}
//FAWE end
}