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

Improve backend error handling #11136

Merged
merged 1 commit into from
Sep 20, 2024
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
18 changes: 14 additions & 4 deletions lib/rust/parser/generate-java/java/org/enso/syntax2/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ private static boolean searchFromDirToTop(Throwable chain, File root, String...
return false;
}

private long state;
private long stateUnlessClosed;

private Parser(long stateIn) {
state = stateIn;
stateUnlessClosed = stateIn;
}

private static native long allocState();
Expand Down Expand Up @@ -115,14 +115,24 @@ public long isIdentOrOperator(CharSequence input) {
return isIdentOrOperator(inputBuf);
}

private long getState() {
if (stateUnlessClosed != 0) {
return stateUnlessClosed;
} else {
throw new IllegalStateException("Parser used after close()");
}
}

public ByteBuffer parseInputLazy(CharSequence input) {
var state = getState();
byte[] inputBytes = input.toString().getBytes(StandardCharsets.UTF_8);
ByteBuffer inputBuf = ByteBuffer.allocateDirect(inputBytes.length);
inputBuf.put(inputBytes);
return parseTreeLazy(state, inputBuf);
}

public Tree parse(CharSequence input) {
var state = getState();
Copy link
Member

Choose a reason for hiding this comment

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

Ok, this kind of robustness check cannot hurt.

byte[] inputBytes = input.toString().getBytes(StandardCharsets.UTF_8);
ByteBuffer inputBuf = ByteBuffer.allocateDirect(inputBytes.length);
inputBuf.put(inputBytes);
Expand All @@ -140,7 +150,7 @@ public static String getWarningMessage(Warning warning) {

@Override
public void close() {
freeState(state);
state = 0;
freeState(stateUnlessClosed);
stateUnlessClosed = 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static Value getType(String moduleName, String typeName) {
var ex =
new NullPointerException(
"Cannot get type for " + moduleName + " type: " + typeName + " at " + module);
ex.initCause(ex);
ex.initCause(e);
Copy link
Member

Choose a reason for hiding this comment

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

Oh, thanks for the catch.

throw ex;
}
}
Expand Down
Loading