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

Show warning when exception occurs while scanning items #32

Merged
merged 1 commit into from
Sep 2, 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
16 changes: 13 additions & 3 deletions qualibrate/qualibration_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,15 @@ def scan_folder_for_instances(
for file in sorted(path.iterdir()):
if not file_is_calibration_instance(file, cls.__name__):
continue
cls.scan_graph_file(file, graphs)
try:
cls.scan_graph_file(file, graphs)
except Exception as e:
warnings.warn(
RuntimeWarning(
"An error occurred on scanning graph file "
f"{file.name}.\nError message: {e}"
)
)
finally:
cls.mode.inspection = inspection
return graphs
Expand Down Expand Up @@ -188,9 +196,11 @@ def completed_count(self) -> int:
)

def _get_all_nodes_parameters(
self, nodes_parameters: Mapping[str, Any]
self, nodes_parameters: Mapping[str, Any]
) -> Mapping[str, Any]:
nodes_class = self.full_parameters_class.model_fields["nodes"].annotation
nodes_class = self.full_parameters_class.model_fields[
"nodes"
].annotation
return {
name: nodes_parameters.get(name, {})
for name in cast(NodesParameters, nodes_class).model_fields.keys()
Expand Down
11 changes: 10 additions & 1 deletion qualibrate/qualibration_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,16 @@ def scan_folder_for_instances(
for file in sorted(path.iterdir()):
if not file_is_calibration_instance(file, cls.__name__):
continue
cls.scan_node_file(file, nodes)
try:
cls.scan_node_file(file, nodes)
except Exception as e:
warnings.warn(
RuntimeWarning(
"An error occurred on scanning node file "
f"{file.name}.\nError: {type(e)}: {e}"
)
)

finally:
cls.mode.inspection = inspection
return nodes
Expand Down