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

feat(kernel): distinguish framework errors from userland errors in Java #3747

Merged
merged 27 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5586bbc
framework errors
comcalvi Sep 1, 2022
db512f8
tmp
comcalvi Sep 7, 2022
d8510a7
playback tests pass
comcalvi Sep 8, 2022
770c120
remove comment
comcalvi Sep 8, 2022
8b81f62
js exception added
comcalvi Sep 9, 2022
3c0dc76
rename
comcalvi Sep 12, 2022
3ed3b27
rename JsiiE
comcalvi Sep 12, 2022
d6975d8
need to ensure that JsErrors are thrown correctly, the writeError() m…
comcalvi Sep 12, 2022
6ed003b
playback fix
comcalvi Sep 13, 2022
428c95e
force js error from kernel host...pretty sure this is the wrong appro…
comcalvi Sep 13, 2022
8dbb87f
working userland errors
comcalvi Sep 13, 2022
3486573
remove old commment
comcalvi Sep 13, 2022
42a4f31
remove commented code
comcalvi Sep 13, 2022
a32e01d
test fix
comcalvi Sep 14, 2022
f116ddb
removed old comment
comcalvi Sep 14, 2022
feecb62
updated expected exception type to JsiiException
comcalvi Sep 14, 2022
da967df
updated type to name
comcalvi Sep 14, 2022
855085d
updated comment
comcalvi Sep 15, 2022
53aa68d
updated comment
comcalvi Sep 15, 2022
3fc61f8
final comment update
comcalvi Sep 15, 2022
dc7562c
rename JsError to JSError
comcalvi Sep 15, 2022
fb8a93f
have to delete the file to change the capitalization...why????
comcalvi Sep 15, 2022
a468d90
final rename
comcalvi Sep 15, 2022
373cae2
Made JsiiException the base error class in Java. JsiiError now repres…
comcalvi Sep 19, 2022
636516d
comment update
comcalvi Sep 19, 2022
fa5398e
review comments
comcalvi Sep 20, 2022
823b1ba
Merge branch 'main' into frameworkerrors
mergify[bot] Sep 21, 2022
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 @@ -6,6 +6,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import software.amazon.jsii.ComplianceSuiteHarness;
import software.amazon.jsii.JsException;
import software.amazon.jsii.JsiiEngine;
import software.amazon.jsii.JsiiException;
import software.amazon.jsii.ReloadingClassLoader;
Expand Down Expand Up @@ -335,7 +336,7 @@ public void exceptions() {
assertEquals(23, calc3.getValue());
boolean thrown = false;
try { calc3.add(10); }
catch (Exception e) { thrown = true; }
catch (JsException e) { thrown = true; }
assertTrue(thrown);
calc3.setMaxValue(40);
calc3.add(10);
Expand Down Expand Up @@ -518,7 +519,7 @@ public String getTheProperty() {
boolean thrown = false;
try {
so.retrieveValueOfTheProperty();
} catch (Exception e) {
} catch (JsiiException e) {
assertTrue(e.getMessage().contains("Oh no, this is bad"));
thrown = true;
}
Expand All @@ -536,7 +537,7 @@ public void setTheProperty(String value) {
boolean thrown = false;
try {
so.modifyValueOfTheProperty("Hii");
} catch (Exception e) {
} catch (JsiiException e) {
assertTrue(e.getMessage().contains("Exception from overloaded setter"));
thrown = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package software.amazon.jsii;

/*
* Represents an irrecoverable error, such as a
comcalvi marked this conversation as resolved.
Show resolved Hide resolved
* broken pipe.
*/
public final class JsException extends JsiiBaseException {

/**
* Creates an exception.
* @param message The error message
*/
JsException(final String message) {
super(message);
}

/**
* Creates an exception.
* @param e The error that caused this exception
*/
JsException(final Throwable e) {
super(e);
}

/**
* Creates an exception.
* @param message The error message
* @param e The error that caused this exception
*/
JsException(final String message, final Throwable e) {
super(message, e);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package software.amazon.jsii;

/**
* An error raised by the jsii runtime.
*/
public abstract class JsiiBaseException extends RuntimeException {
public static enum Type {
JSII_FAULT("@jsii/kernel.Fault"),
JS_EXCEPTION("@jsii/kernel.JSError");

private final String errorType;

Type(String str) {
this.errorType = str;
}

public String toString() {
return this.errorType;
}
}
public static final long serialVersionUID = 1L;

/**
* Creates an exception.
* @param message The error message
*/
JsiiBaseException(final String message) {
super(message);
}

/**
* Creates an exception.
* @param e The error that caused this exception
*/
JsiiBaseException(final Throwable e) {
super(e);
}

/**
* Creates an exception.
* @param message The error message
* @param e The error that caused this exception
*/
JsiiBaseException(final String message, final Throwable e) {
super(message, e);
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
package software.amazon.jsii;

/**
* An error raised by the jsii runtime.
/*
* Represents an irrecoverable error, likely thrown from the kernel.
*/
public final class JsiiException extends RuntimeException {
comcalvi marked this conversation as resolved.
Show resolved Hide resolved
public static final long serialVersionUID = 1L;
public final class JsiiException extends JsiiBaseException {

/**
* Creates an exception.
* @param message The error message
*/
JsiiException(final String message) {
super(message);
}
/**
* 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 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);
}
/**
* 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,22 @@ JsonNode requestResponse(final JsonNode request) {

/**
* Handles an "error" response by extracting the message and stack trace
* and throwing a JsiiException.
* and throwing a JsiiException or a JsException.
*
* @param resp The response
* @return Never
*/
private JsonNode processErrorResponse(final JsonNode resp) {
String errorName = resp.get("name").asText();
String errorMessage = resp.get("error").asText();
if (resp.has("stack")) {
errorMessage += "\n" + resp.get("stack").asText();
}

if (errorName.equals(JsiiException.Type.JS_EXCEPTION.toString())) {
throw new JsException(errorMessage);
}

throw new JsiiException(errorMessage);
}

Expand Down
Loading