Skip to content

Commit a6db142

Browse files
committed
this should work a lot better
1 parent 7a076da commit a6db142

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

common/src/main/java/revxrsal/commands/node/DefaultFailureHandler.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import revxrsal.commands.Lamp;
66
import revxrsal.commands.command.CommandActor;
77
import revxrsal.commands.command.Potential;
8+
import revxrsal.commands.exception.ExpectedLiteralException;
89
import revxrsal.commands.exception.NoPermissionException;
910
import revxrsal.commands.stream.StringStream;
1011

1112
import java.util.List;
1213

1314
import static revxrsal.commands.util.Collections.any;
15+
import static revxrsal.commands.util.Collections.filter;
1416

1517
/**
1618
* The default failure handler. This can be overridden in {@link DispatcherSettings}
@@ -39,16 +41,18 @@ public void handleFailedAttempts(@NotNull A actor, @NotNull @Unmodifiable List<P
3941
failedAttempts.get(0).handleException();
4042
return;
4143
}
42-
if (failedAttempts.get(0).error() instanceof NoPermissionException) {
43-
failedAttempts.get(0).handleException();
44-
return;
45-
}
46-
actor.error("Failed to find a suitable command for your input (\"" + input.source() + "\"). Did you mean:");
47-
for (int i = 0; i < failedAttempts.size(); i++) {
48-
if (i >= MAX_NUMBER_OF_SUGGESTIONS)
49-
break;
50-
Potential<A> failedAttempt = failedAttempts.get(i);
51-
actor.reply("- " + failedAttempt.context().command().path());
44+
45+
List<Potential<A>> realExceptions = filter(failedAttempts, v -> !(v.error() instanceof ExpectedLiteralException));
46+
if (realExceptions.isEmpty()) {
47+
actor.error("Failed to find a suitable command for your input (\"" + input.source() + "\"). Did you mean:");
48+
for (int i = 0; i < failedAttempts.size(); i++) {
49+
if (i >= MAX_NUMBER_OF_SUGGESTIONS)
50+
break;
51+
Potential<A> failedAttempt = failedAttempts.get(i);
52+
actor.reply("- " + failedAttempt.context().command().path());
53+
}
54+
} else {
55+
realExceptions.get(0).handleException();
5256
}
5357
}
5458
}

0 commit comments

Comments
 (0)