Skip to content

Commit

Permalink
feat: Improve error reporting and fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeschamps committed Oct 22, 2024
1 parent 0fadfb0 commit 35f1430
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
11 changes: 4 additions & 7 deletions src/careamics_napari/training_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ def _update_from_prediction(self, update: PredictionUpdate) -> None:

if _has_napari:
ntf.show_error(
"An error occurred during prediction. Check the console for more "
"information. Note: if you get an error due to the sizes of "
"Tensors, try using tiling."
f"An error occurred during prediction: \n {update.value} \n"
f"Note: if you get an error due to the sizes of "
f"Tensors, try using tiling."
)

else:
Expand All @@ -365,11 +365,8 @@ def _update_from_saving(self, update: SavingUpdate) -> None:
elif update.type == SavingUpdateType.EXCEPTION:
self.save_status.state = SavingState.CRASHED

# print exception without raising it
print(f"Error: {update.value}")

if _has_napari:
ntf.show_error("An error occurred during saving.")
ntf.show_error(f"An error occurred during saving: \n {update.value}")

def _set_data_from_algorithm(self, name: str) -> None:
"""Update the data selection widget based on the algorithm.
Expand Down
2 changes: 1 addition & 1 deletion src/careamics_napari/widgets/predict_data_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _update_pred_layer(self: Self, layer: Image) -> None:
layer : Image
The selected layer.
"""
if self.config_signal.layer_pred is not None:
if self.config_signal is not None:
self.config_signal.layer_pred = layer

def _update_pred_folder(self: Self, folder: str) -> None:
Expand Down
1 change: 0 additions & 1 deletion src/careamics_napari/widgets/train_data_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def _set_layer_tab(

# tool tips
self.target_train.native.setToolTip("Select a training target layer.")

self.target_val.native.setToolTip("Select a validation target layer.")

# connection actions for targets
Expand Down
10 changes: 10 additions & 0 deletions src/careamics_napari/workers/prediction_worker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""A thread worker function running CAREamics prediction."""

import traceback
from collections.abc import Generator
from queue import Queue
from threading import Thread
Expand Down Expand Up @@ -75,6 +76,11 @@ def _push_exception(queue: Queue, e: Exception) -> None:
e : Exception
Exception.
"""
try:
raise e
except Exception as _:
traceback.print_exc()

queue.put(PredictionUpdate(PredictionUpdateType.EXCEPTION, e))


Expand Down Expand Up @@ -108,6 +114,7 @@ def _predict(
_push_exception(
update_queue, ValueError("Prediction layer has not been selected.")
)
return

elif config_signal.layer_pred.data is None:
_push_exception(
Expand All @@ -116,6 +123,7 @@ def _predict(
f"Prediction layer {config_signal.layer_pred.name} is empty."
),
)
return
else:
pred_data = config_signal.layer_pred.data

Expand Down Expand Up @@ -173,6 +181,8 @@ def _predict(
# time.sleep(0.2)

except Exception as e:
traceback.print_exc()

update_queue.put(PredictionUpdate(PredictionUpdateType.EXCEPTION, e))
return

Expand Down
3 changes: 3 additions & 0 deletions src/careamics_napari/workers/saving_worker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""A thread worker function running CAREamics prediction."""

import traceback
from collections.abc import Generator

from careamics import CAREamist
Expand Down Expand Up @@ -59,6 +60,8 @@ def save_worker(
)

except Exception as e:
traceback.print_exc()

yield SavingUpdate(SavingUpdateType.EXCEPTION, e)

yield SavingUpdate(SavingUpdateType.STATE, SavingState.DONE)
3 changes: 3 additions & 0 deletions src/careamics_napari/workers/training_worker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""A thread worker function running CAREamics training."""

import traceback
from collections.abc import Generator
from queue import Queue
from threading import Thread
Expand Down Expand Up @@ -250,6 +251,8 @@ def _train(
# time.sleep(0.2)

except Exception as e:
traceback.print_exc()

training_queue.put(TrainUpdate(TrainUpdateType.EXCEPTION, e))

training_queue.put(TrainUpdate(TrainUpdateType.STATE, TrainingState.DONE))

0 comments on commit 35f1430

Please sign in to comment.