Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RemoteException emits more safeargs #655

Merged
merged 3 commits into from
Apr 28, 2021
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
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-655.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: RemoteExceptions now emit SafeArgs for `errorInstanceId`, `errorCode` and `errorName` (previously it was just `errorInstanceId`)
links:
- https://github.com/palantir/conjure-java-runtime-api/pull/655
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
import com.palantir.logsafe.Arg;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.SafeLoggable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/** An exception thrown by an RPC client to indicate remote/server-side failure. */
public final class RemoteException extends RuntimeException implements SafeLoggable {
private static final long serialVersionUID = 1L;
private static final String ERROR_INSTANCE_ID = "errorInstanceId";
private static final String ERROR_CODE = "errorCode";
private static final String ERROR_NAME = "errorName";

private final String message;
private final String stableMessage;
Expand All @@ -49,7 +53,10 @@ public RemoteException(SerializableError error, int status) {
this.message = this.stableMessage + " with instance ID " + error.errorInstanceId();
this.error = error;
this.status = status;
this.args = Collections.singletonList(SafeArg.of("errorInstanceId", error.errorInstanceId()));
this.args = Collections.unmodifiableList(Arrays.asList(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ImmutableList is off the cards cos this project doens't seem to depend on guava, and we still have sourceCompat = 1.8 here so no List.of either.

SafeArg.of(ERROR_INSTANCE_ID, error.errorInstanceId()),
SafeArg.of(ERROR_NAME, error.errorName()),
SafeArg.of(ERROR_CODE, error.errorCode())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public void testArgsIsEmpty() {
.putParameters("param", "value")
.build(),
500);
assertThat(remoteException.getArgs()).containsExactly(SafeArg.of("errorInstanceId", "errorId"));
assertThat(remoteException.getArgs())
.containsExactlyInAnyOrder(
SafeArg.of("errorInstanceId", "errorId"),
SafeArg.of("errorCode", "errorCode"),
SafeArg.of("errorName", "errorName"));
}
}