-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kernel): distinguish framework errors from userland errors in Ja…
…va (#3747) Adds the `JsiiFault` and `JsError` types to the Kernel and corresponding types in Java. This will provide a better error experience and make it clearer which errors come from the jsii framework itself (eg a broken pipe) and which errors from the user code (eg a CDK construct validation error). --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
- Loading branch information
Showing
16 changed files
with
240 additions
and
139 deletions.
There are no files selected for viewing
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
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
34 changes: 34 additions & 0 deletions
34
packages/@jsii/java-runtime/project/src/main/java/software/amazon/jsii/JsiiError.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,34 @@ | ||
package software.amazon.jsii; | ||
|
||
/** | ||
* A nonrecoverable error from the jsii runtime, | ||
* usually the kernel. | ||
*/ | ||
public final class JsiiError extends JsiiException { | ||
public static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* Creates an exception. | ||
* @param message The error message | ||
*/ | ||
JsiiError(final String message) { | ||
super(message); | ||
} | ||
|
||
/** | ||
* Creates an exception. | ||
* @param e The error that caused this exception | ||
*/ | ||
JsiiError(final Throwable e) { | ||
super(e); | ||
} | ||
|
||
/** | ||
* Creates an exception. | ||
* @param message The error message | ||
* @param e The error that caused this exception | ||
*/ | ||
JsiiError(final String message, final Throwable e) { | ||
super(message, e); | ||
} | ||
} |
61 changes: 38 additions & 23 deletions
61
packages/@jsii/java-runtime/project/src/main/java/software/amazon/jsii/JsiiException.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 |
---|---|---|
@@ -1,33 +1,48 @@ | ||
package software.amazon.jsii; | ||
|
||
/** | ||
/* | ||
* An error raised by the jsii runtime. | ||
*/ | ||
public final class JsiiException extends RuntimeException { | ||
public abstract class JsiiException extends RuntimeException { | ||
public static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* Creates an exception. | ||
* @param message The error message | ||
*/ | ||
JsiiException(final String message) { | ||
super(message); | ||
} | ||
static enum Type { | ||
JSII_FAULT("@jsii/kernel.Fault"), | ||
RUNTIME_EXCEPTION("@jsii/kernel.RuntimeException"); | ||
|
||
/** | ||
* Creates an exception. | ||
* @param e The error that caused this exception | ||
*/ | ||
JsiiException(final Throwable e) { | ||
super(e); | ||
} | ||
private final String errorType; | ||
|
||
Type(String str) { | ||
this.errorType = str; | ||
} | ||
|
||
/** | ||
* Creates an exception. | ||
* @param message The error message | ||
* @param e The error that caused this exception | ||
*/ | ||
JsiiException(final String message, final Throwable e) { | ||
super(message, e); | ||
public String toString() { | ||
return this.errorType; | ||
} | ||
} | ||
|
||
/** | ||
* Creates an exception. | ||
* @param message The error message | ||
*/ | ||
JsiiException(final String message) { | ||
super(message); | ||
} | ||
|
||
/** | ||
* Creates an exception. | ||
* @param e The error that caused this exception | ||
*/ | ||
JsiiException(final Throwable e) { | ||
super(e); | ||
} | ||
|
||
/** | ||
* Creates an exception. | ||
* @param message The error message | ||
* @param e The error that caused this exception | ||
*/ | ||
JsiiException(final String message, final Throwable e) { | ||
super(message, e); | ||
} | ||
} |
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
Oops, something went wrong.