-
Notifications
You must be signed in to change notification settings - Fork 33
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
adding custom ConjureDefined exception types #1246
Draft
mpritham
wants to merge
3
commits into
develop
Choose a base branch
from
pm/conjure-errors
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
errors/src/main/java/com/palantir/conjure/java/api/errors/ConjureDefinedError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.palantir.conjure.java.api.errors; | ||
|
||
import com.palantir.logsafe.Arg; | ||
import com.palantir.logsafe.SafeLoggable; | ||
|
||
// TODO(pm): according to java docs on Error an "Error - indicates serious problems that a reasonable application should | ||
// not try to catch." Perhaps this isn't a good name, but we've already called something SerializableError and the | ||
// "error" matches the conjure concept so this seems fine but check if folks care. | ||
// TODO(pm): copy-paste the ServiceException logic. I don't like extending ServiceException because we have | ||
// (instanceof ServiceException) checks scattered across a few repos. Enumerate them, and see if they need to be | ||
// handled differently compared to ServiceException. | ||
public final class ConjureDefinedError extends ServiceException implements SafeLoggable { | ||
public ConjureDefinedError(ErrorType errorType, Arg<?>... parameters) { | ||
super(errorType, parameters); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
errors/src/main/java/com/palantir/conjure/java/api/errors/ConjureDefinedRemoteException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.palantir.conjure.java.api.errors; | ||
|
||
// TODO(pm): copy-paste RemoteException logic. we have instanceof checks scattered across a few repos that we should be | ||
// intentional about. | ||
public final class ConjureDefinedRemoteException extends RemoteException { | ||
public ConjureDefinedRemoteException(SerializableError error, int status) { | ||
super(error, status); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,12 +26,13 @@ | |
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.palantir.logsafe.Arg; | ||
import com.palantir.logsafe.exceptions.SafeIllegalStateException; | ||
import org.immutables.value.Value; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import org.immutables.value.Value; | ||
|
||
/** | ||
* A JSON-serializable representation of an exception/error, represented by its error code, an error name identifying | ||
|
@@ -129,6 +130,19 @@ public static SerializableError forException(ServiceException exception) { | |
return builder.build(); | ||
} | ||
|
||
public static SerializableError forExceptionWithSerializedArgs(ServiceException exception) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't necessarily need to reuse the |
||
Builder builder = new Builder() | ||
.errorCode(exception.getErrorType().code().name()) | ||
.errorName(exception.getErrorType().name()) | ||
.errorInstanceId(exception.getErrorInstanceId()); | ||
|
||
for (Arg<?> arg : exception.getArgs()) { | ||
builder.putParameters(arg.getName(), Objects.toString(arg.getValue())); | ||
} | ||
|
||
return builder.build(); | ||
} | ||
|
||
// TODO(rfink): Remove once all error producers have switched to errorCode/errorName. | ||
public static final class Builder extends ImmutableSerializableError.Builder {} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a checked exception? Extending
ServiceException
means we're also extendingRuntimeException
, which means it's unchecked.