Skip to content

Commit

Permalink
Catch only specific exception
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonHeybrock committed Nov 7, 2023
1 parent 1a2f313 commit 0a4cab2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/scippnexus/nxtransformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ class TransformationChainResolver:
class follows the paths and resolves the chain of transformations.
"""

class ChainError(KeyError):
"""Raised when a transformation chain cannot be resolved."""

pass

def __init__(self, stack: List[sc.DataGroup]):
self._stack = stack

Expand All @@ -215,7 +220,9 @@ def root(self) -> TransformationChainResolver:
@property
def parent(self) -> TransformationChainResolver:
if len(self._stack) == 1:
raise KeyError("Transformation depends on node beyond root")
raise TransformationChainResolver.ChainError(
"Transformation depends on node beyond root"
)
return TransformationChainResolver(self._stack[:-1])

@property
Expand Down Expand Up @@ -368,7 +375,7 @@ def _with_positions(
out[store_position] = transform * sc.vector([0, 0, 0], unit='m')
if store_transform is not None:
out[store_transform] = transform
except KeyError:
except TransformationChainResolver.ChainError:
pass
for name, value in dg.items():
if isinstance(value, sc.DataGroup):
Expand Down

0 comments on commit 0a4cab2

Please sign in to comment.