Skip to content

Commit 8f7fd34

Browse files
committed
Add max-error-length config option
1 parent 5bf0e9b commit 8f7fd34

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

api/src/main/java/com/viaversion/viaversion/api/configuration/ViaVersionConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,4 +498,11 @@ public interface ViaVersionConfig extends Config {
498498
* @return true if enabled
499499
*/
500500
boolean cancelSwingInInventory();
501+
502+
/**
503+
* Returns the max length of error messages. Longer messages will be truncated unless in debug mode.
504+
*
505+
* @return the max length of error messages
506+
*/
507+
int maxErrorLength();
501508
}

api/src/main/java/com/viaversion/viaversion/exception/InformativeException.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.checkerframework.checker.nullness.qual.Nullable;
3030

3131
public class InformativeException extends RuntimeException {
32-
private static final int MAX_MESSAGE_LENGTH = 5_000;
3332
private final List<DataEntry> dataEntries = new ArrayList<>();
3433
private boolean shouldBePrinted = true;
3534
private int sources;
@@ -72,8 +71,8 @@ public String getMessage() {
7271

7372
builder.append(entry.name()).append(": ");
7473
String s = String.valueOf(entry.value());
75-
if (!Via.getManager().isDebug() && s.length() > 10 && builder.length() + s.length() > MAX_MESSAGE_LENGTH) {
76-
final int remaining = Math.max(0, MAX_MESSAGE_LENGTH - builder.length());
74+
if (!Via.getManager().isDebug() && s.length() > 10 && builder.length() + s.length() > Via.getConfig().maxErrorLength()) {
75+
final int remaining = Math.max(0, Via.getConfig().maxErrorLength() - builder.length());
7776
s = s.substring(0, Math.min(remaining, s.length())) + "...";
7877
}
7978
builder.append(StringUtil.forLogging(s));

common/src/main/java/com/viaversion/viaversion/configuration/AbstractViaConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
9797
private boolean hideScoreboardNumbers;
9898
private boolean fix1_21PlacementRotation;
9999
private boolean cancelSwingInInventory;
100+
private int maxErrorLength;
100101

101102
protected AbstractViaConfig(final File configFile, final Logger logger) {
102103
super(configFile, logger);
@@ -165,6 +166,7 @@ protected void loadFields() {
165166
cancelSwingInInventory = getBoolean("cancel-swing-in-inventory", true);
166167
packetTrackerConfig = loadRateLimitConfig(getSection("packet-limiter"), "%pps", 1);
167168
packetSizeTrackerConfig = loadRateLimitConfig(getSection("packet-size-limiter"), "%bps", 1024);
169+
maxErrorLength = getInt("max-error-length", 1500);
168170
}
169171

170172
protected void updateConfig() {
@@ -606,4 +608,9 @@ public boolean fix1_21PlacementRotation() {
606608
public boolean cancelSwingInInventory() {
607609
return cancelSwingInInventory;
608610
}
611+
612+
@Override
613+
public int maxErrorLength() {
614+
return maxErrorLength;
615+
}
609616
}

common/src/main/java/com/viaversion/viaversion/protocol/packet/PacketWrapperImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.viaversion.viaversion.api.type.Types;
3333
import com.viaversion.viaversion.exception.CancelException;
3434
import com.viaversion.viaversion.exception.InformativeException;
35+
import com.viaversion.viaversion.util.ArrayUtil;
3536
import com.viaversion.viaversion.util.PipelineUtil;
3637
import io.netty.buffer.ByteBuf;
3738
import io.netty.channel.ChannelFuture;
@@ -624,7 +625,7 @@ public int hashCode() {
624625

625626
@Override
626627
public String toString() {
627-
return "{" + type + ": " + value + "}";
628+
return "{" + type + ": " + ArrayUtil.toString(value) + "}";
628629
}
629630
}
630631
}

common/src/main/resources/assets/viaversion/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ reload-disconnect-msg: "Server reload, please rejoin!"
3131
suppress-conversion-warnings: false
3232
# This can be disabled for debugging purposes if text in chat/entities/items shows an error tag.
3333
suppress-text-component-conversion-warnings: true
34+
# Maximum length of error messages in the console.
35+
max-error-length: 1500
3436
#
3537
#----------------------------------------------------------#
3638
# VELOCITY OPTIONS #

0 commit comments

Comments
 (0)