Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public void onServerException(final ServerExceptionEvent event) {
if (!(event.getException() instanceof final ServerPluginException exception)) return;
if (!exception.getResponsiblePlugin().equals(metrics.plugin())) return;
final var report = exception.getCause() != null ? exception.getCause() : exception;
metrics.getErrorTracker().ifPresent(tracker -> tracker.trackError(report));
metrics.getErrorTracker().ifPresent(tracker -> tracker.trackError(report, false));
}
}
3 changes: 2 additions & 1 deletion core/src/main/java/dev/faststats/core/ErrorHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class ErrorHelper {
private static final int STACK_TRACE_LENGTH = Math.min(500, Integer.getInteger("faststats.stack-trace-length", 300));
private static final int STACK_TRACE_LIMIT = Math.min(50, Integer.getInteger("faststats.stack-trace-limit", 15));

public static JsonObject compile(final Throwable error, @Nullable final List<String> suppress) {
public static JsonObject compile(final Throwable error, @Nullable final List<String> suppress, final boolean handled) {
final var report = new JsonObject();
final var message = getAnonymizedMessage(error);

Expand All @@ -40,6 +40,7 @@ public static JsonObject compile(final Throwable error, @Nullable final List<Str
if (message != null) report.addProperty("message", message);

report.add("stack", stacktrace);
report.addProperty("handled", true);

return report;
}
Expand Down
35 changes: 31 additions & 4 deletions core/src/main/java/dev/faststats/core/ErrorTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public sealed interface ErrorTracker permits SimpleErrorTracker {
*
* @return the error tracker
* @see #contextUnaware()
* @see #trackError(String)
* @see #trackError(Throwable)
* @see #trackError(String, boolean)
* @see #trackError(Throwable, boolean)
* @since 0.10.0
*/
@Contract(value = " -> new")
Expand Down Expand Up @@ -51,24 +51,51 @@ static ErrorTracker contextUnaware() {
}

/**
* Tracks an error.
* Tracks a handled error.
*
* @param message the error message
* @see #trackError(Throwable)
* @see #trackError(String, boolean)
* @since 0.10.0
*/
@Contract(mutates = "this")
void trackError(String message);

/**
* Tracks an error.
* Tracks a handled error.
*
* @param error the error
* @see #trackError(Throwable, boolean)
* @since 0.10.0
*/
@Contract(mutates = "this")
void trackError(Throwable error);

/**
* Tracks an error.
* <p>
* A {@code handled=true} error is expected and properly handled.
*
* @param message the error message
* @param handled whether the error was handled
* @see #trackError(Throwable, boolean)
* @since 0.20.0
*/
@Contract(mutates = "this")
void trackError(String message, boolean handled);

/**
* Tracks an error.
* <p>
* A {@code handled=true} error is expected and properly handled.
*
* @param error the error
* @param handled whether the error was handled
* @since 0.20.0
*/
@Contract(mutates = "this")
void trackError(Throwable error, boolean handled);

/**
* Attaches an error context to the tracker.
* <p>
Expand Down
18 changes: 14 additions & 4 deletions core/src/main/java/dev/faststats/core/SimpleErrorTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,23 @@ final class SimpleErrorTracker implements ErrorTracker {

@Override
public void trackError(final String message) {
trackError(new RuntimeException(message));
trackError(message, true);
}

@Override
public void trackError(final Throwable error) {
trackError(error, true);
}

@Override
public void trackError(final String message, final boolean handled) {
trackError(new RuntimeException(message), handled);
}

@Override
public void trackError(final Throwable error, final boolean handled) {
try {
final var compiled = ErrorHelper.compile(error, null);
final var compiled = ErrorHelper.compile(error, null, handled);
final var hashed = MurmurHash3.hash(compiled);
if (collected.compute(hashed, (k, v) -> {
return v == null ? 1 : v + 1;
Expand Down Expand Up @@ -84,9 +94,9 @@ public synchronized void attachErrorContext(@Nullable final ClassLoader loader)
if (loader != null && !ErrorTracker.isSameLoader(loader, error)) return;
final var event = errorEvent;
if (event != null) event.accept(loader, error);
trackError(error);
trackError(error, false);
} catch (final Throwable t) {
trackError(t);
trackError(t, false);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.19.0
version=0.20.0