Skip to content

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
krasinski committed Oct 21, 2024
1 parent d5bebbc commit 3342ed8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
4 changes: 2 additions & 2 deletions h2o-algos/src/main/java/water/tools/MojoConvertTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public static void main(String[] args) throws IOException {
}

public static void mainInternal(String[] args) throws IOException {
if (args.length < 2) {
if (args.length < 2 || args[0] == null || args[1] == null) {
throw new IllegalArgumentException("java -cp h2o.jar " + MojoConvertTool.class.getName() + " source_mojo.zip target_pojo.java");
}

File mojoFile = new File(args[0]);
if (!mojoFile.isFile()) {
if (!mojoFile.exists() || !mojoFile.isFile()) {
throw new IllegalArgumentException("Specified MOJO file (" + mojoFile.getAbsolutePath() + ") doesn't exist!");
}
File pojoFile = new File(args[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ public ValStr apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
Method mainMethod = clazz.getDeclaredMethod("mainInternal", String[].class);
mainMethod.invoke(null, new Object[]{args});
} catch (Exception e) {
throw new RuntimeException("Error calling " + toolClassName + "(" + e.getClass().getName() + ")") {
@Override
public synchronized Throwable fillInStackTrace() {
return this;
}
};
RuntimeException shorterException = new RuntimeException(e.getCause().getMessage());
shorterException.setStackTrace(new StackTraceElement[0]);
throw shorterException;
}
return new ValStr("OK");
}
Expand Down

0 comments on commit 3342ed8

Please sign in to comment.