Skip to content

fix: add fix error message in Error thrown by API #164

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

Merged
merged 6 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions java/src/main/java/com/kcl/api/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.Map;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;

Expand Down Expand Up @@ -651,15 +652,17 @@ public GetVersion_Result getVersion(GetVersion_Args args) throws Exception {
private byte[] call(String name, byte[] args) throws Exception {
byte[] result = callNative(name.getBytes(), args);
if (result != null && startsWith(result, ERROR_PREFIX)) {
throw new java.lang.Error(result.toString().substring(ERROR_PREFIX.length()).trim());
String resultString = new String(result, StandardCharsets.UTF_8);
throw new Exception(resultString.substring(ERROR_PREFIX.length()).trim());
}
return result;
}

private byte[] callLoadPackageWithCache(byte[] args) throws Exception {
byte[] result = loadPackageWithCache(args);
if (result != null && startsWith(result, ERROR_PREFIX)) {
throw new java.lang.Error(result.toString().substring(ERROR_PREFIX.length()).trim());
String resultString = new String(result, StandardCharsets.UTF_8);
throw new Exception(resultString.substring(ERROR_PREFIX.length()).trim());
}
return result;
}
Expand Down
12 changes: 12 additions & 0 deletions java/src/test/java/com/kcl/ExecProgramTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,16 @@ public void testExecProgramApi() throws Exception {
ExecProgram_Result result = apiInstance.execProgram(args);
Assert.assertEquals(result.getYamlResult(), "app:\n" + " replicas: 2");
}

@Test
public void testExecProgramApiInvalid() {
try {
ExecProgram_Args args = ExecProgram_Args.newBuilder().build();

API apiInstance = new API();
apiInstance.execProgram(args);
} catch (Exception e) {
Assert.assertEquals(e.getMessage(), "No input KCL files or paths");
}
}
}
Loading