Skip to content

Commit

Permalink
Remove unnecessary exception logs in AbstractContextAwareFuture (#5328
Browse files Browse the repository at this point in the history
)

Motivation:

When a decorator using `ctx.makeContextAware()` throws an exception in `handle()`, `AbstractContextAwareFuture` will log a misleading `An error occurred while pushing a context`. Instead, we shouldn't log anything.

This was an accidental side effect of a726fd3#diff-4ad33a0c0d9becf6780837efb73386e5547723d537f79a22e313118e78a67d38

Modifications:

- Remove warn logs for upstream exceptions in `AbstractContextAwareFuture`, and only log `context.push()` exceptions

Result:

- We no longer see misleading logs when throwing exceptions in `ContextAwareFuture.handle()` and other methods
  • Loading branch information
KarboniteKream authored Dec 8, 2023
1 parent efca3c5 commit a0197b5
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,38 @@ protected final <I, U, V> BiFunction<I, U, V> makeContextAwareLoggingException(B
return (t, u) -> makeContextAwareLoggingException0(() -> fn.apply(t, u));
}

@SuppressWarnings("MustBeClosedChecker")
private void makeContextAwareLoggingException0(Runnable action) {
try (SafeCloseable ignored = context.push()) {
action.run();
final SafeCloseable handle;
try {
handle = context.push();
} catch (Throwable th) {
logger.warn("An error occurred while pushing a context", th);
throw th;
}

try {
action.run();
} finally {
handle.close();
}
}

@SuppressWarnings("MustBeClosedChecker")
private <V> V makeContextAwareLoggingException0(Supplier<? extends V> fn) {
try (SafeCloseable ignored = context.push()) {
return fn.get();
final SafeCloseable handle;
try {
handle = context.push();
} catch (Throwable th) {
logger.warn("An error occurred while pushing a context", th);
throw th;
}

try {
return fn.get();
} finally {
handle.close();
}
}

@Override
Expand Down

0 comments on commit a0197b5

Please sign in to comment.