Skip to content

Commit

Permalink
more explicit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Dec 4, 2024
1 parent af521fb commit 41de3eb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
58 changes: 29 additions & 29 deletions src/main/java/ai/nets/samj/models/AbstractSamJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,11 @@ void setImage(RandomAccessibleInterval<T> rai) throws IOException, RuntimeExcept
Task task = python.task(script);
task.waitFor();
if (task.status == TaskStatus.CANCELED)
throw new RuntimeException();
throw new RuntimeException("Task canceled");
else if (task.status == TaskStatus.FAILED)
throw new RuntimeException();
throw new RuntimeException(task.error);
else if (task.status == TaskStatus.CRASHED)
throw new RuntimeException();
throw new RuntimeException(task.error);
this.shma.close();
} catch (IOException | InterruptedException | RuntimeException e) {
try {
Expand All @@ -335,11 +335,11 @@ private void reencodeCrop(long[] cropSize) throws IOException, InterruptedExcept
Task task = python.task(script);
task.waitFor();
if (task.status == TaskStatus.CANCELED)
throw new RuntimeException();
throw new RuntimeException("Task canceled");
else if (task.status == TaskStatus.FAILED)
throw new RuntimeException();
throw new RuntimeException(task.error);
else if (task.status == TaskStatus.CRASHED)
throw new RuntimeException();
throw new RuntimeException(task.error);
this.shma.close();
} catch (IOException | InterruptedException | RuntimeException e) {
try {
Expand Down Expand Up @@ -413,19 +413,19 @@ else if (task.message.equals(UPDATE_ID_CONTOUR)) {
});
task.waitFor();
if (task.status == TaskStatus.CANCELED)
throw new RuntimeException();
throw new RuntimeException("Task canceled");
else if (task.status == TaskStatus.FAILED)
throw new RuntimeException();
throw new RuntimeException(task.error);
else if (task.status == TaskStatus.CRASHED)
throw new RuntimeException();
throw new RuntimeException(task.error);
else if (task.status != TaskStatus.COMPLETE)
throw new RuntimeException();
throw new RuntimeException(task.error);
else if (task.outputs.get("contours_x") == null)
throw new RuntimeException();
throw new RuntimeException("No 'contours_x' output found");
else if (task.outputs.get("contours_y") == null)
throw new RuntimeException();
throw new RuntimeException("No 'contours_y' output found");
else if (task.outputs.get("rle") == null)
throw new RuntimeException();
throw new RuntimeException("No 'rle' outputs found");
callback.updateProgress(Integer.parseInt((String) task.outputs.get("n")));
results = task.outputs;
} catch (InterruptedException | RuntimeException e) {
Expand Down Expand Up @@ -461,19 +461,19 @@ private List<Mask> processAndRetrieveContours(HashMap<String, Object> inputs)
Task task = python.task(script, inputs);
task.waitFor();
if (task.status == TaskStatus.CANCELED)
throw new RuntimeException();
throw new RuntimeException("Task canceled");
else if (task.status == TaskStatus.FAILED)
throw new RuntimeException();
throw new RuntimeException(task.error);
else if (task.status == TaskStatus.CRASHED)
throw new RuntimeException();
throw new RuntimeException(task.error);
else if (task.status != TaskStatus.COMPLETE)
throw new RuntimeException();
throw new RuntimeException(task.error);
else if (task.outputs.get("contours_x") == null)
throw new RuntimeException();
throw new RuntimeException("No 'contours_x' output found");
else if (task.outputs.get("contours_y") == null)
throw new RuntimeException();
throw new RuntimeException("No 'outputs_y' ouptut found");
else if (task.outputs.get("rle") == null)
throw new RuntimeException();
throw new RuntimeException("No 'rle' outputs found");
results = task.outputs;
} catch (InterruptedException | RuntimeException e) {
throw e;
Expand Down Expand Up @@ -1177,11 +1177,11 @@ public String persistEncoding() throws IOException, InterruptedException {
Task task = python.task(saveEncodings);
task.waitFor();
if (task.status == TaskStatus.CANCELED)
throw new RuntimeException();
throw new RuntimeException("Task canceled");
else if (task.status == TaskStatus.FAILED)
throw new RuntimeException();
throw new RuntimeException(task.error);
else if (task.status == TaskStatus.CRASHED)
throw new RuntimeException();
throw new RuntimeException(task.error);
} catch (IOException | InterruptedException | RuntimeException e) {
throw e;
}
Expand All @@ -1197,11 +1197,11 @@ public void selectEncoding(String encodingName) throws IOException, InterruptedE
Task task = python.task(setEncoding);
task.waitFor();
if (task.status == TaskStatus.CANCELED)
throw new RuntimeException();
throw new RuntimeException("Task canceled");
else if (task.status == TaskStatus.FAILED)
throw new RuntimeException();
throw new RuntimeException(task.error);
else if (task.status == TaskStatus.CRASHED)
throw new RuntimeException();
throw new RuntimeException(task.error);
} catch (IOException | InterruptedException | RuntimeException e) {
throw e;
}
Expand All @@ -1217,11 +1217,11 @@ public void deleteEncoding(String encodingName) throws IOException, InterruptedE
Task task = python.task(returnEncoding);
task.waitFor();
if (task.status == TaskStatus.CANCELED)
throw new RuntimeException();
throw new RuntimeException("Task canceled");
else if (task.status == TaskStatus.FAILED)
throw new RuntimeException();
throw new RuntimeException(task.error);
else if (task.status == TaskStatus.CRASHED)
throw new RuntimeException();
throw new RuntimeException(task.error);
} catch (IOException | InterruptedException | RuntimeException e) {
throw e;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/ai/nets/samj/models/EfficientSamJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ private EfficientSamJ(SamEnvManagerAbstract manager,
Task task = python.task(IMPORTS_FORMATED + PythonMethods.RLE_METHOD + PythonMethods.TRACE_EDGES);
task.waitFor();
if (task.status == TaskStatus.CANCELED)
throw new RuntimeException();
throw new RuntimeException("Task canceled");
else if (task.status == TaskStatus.FAILED)
throw new RuntimeException();
throw new RuntimeException(task.error);
else if (task.status == TaskStatus.CRASHED)
throw new RuntimeException();
throw new RuntimeException(task.error);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/ai/nets/samj/models/EfficientViTSamJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ private EfficientViTSamJ(SamEnvManagerAbstract manager, String type,
Task task = python.task(IMPORTS_FORMATED + PythonMethods.RLE_METHOD + PythonMethods.TRACE_EDGES);
task.waitFor();
if (task.status == TaskStatus.CANCELED)
throw new RuntimeException();
throw new RuntimeException("Task canceled");
else if (task.status == TaskStatus.FAILED)
throw new RuntimeException();
throw new RuntimeException(task.error);
else if (task.status == TaskStatus.CRASHED)
throw new RuntimeException();
throw new RuntimeException(task.error);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/ai/nets/samj/models/Sam2.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ private Sam2(SamEnvManagerAbstract manager, String type,
Task task = python.task(IMPORTS_FORMATED + PythonMethods.RLE_METHOD + PythonMethods.TRACE_EDGES);
task.waitFor();
if (task.status == TaskStatus.CANCELED)
throw new RuntimeException();
throw new RuntimeException("Task canceled");
else if (task.status == TaskStatus.FAILED)
throw new RuntimeException();
throw new RuntimeException(task.error);
else if (task.status == TaskStatus.CRASHED)
throw new RuntimeException();
throw new RuntimeException(task.error);
}

/**
Expand Down

0 comments on commit 41de3eb

Please sign in to comment.