Skip to content

Commit

Permalink
handling of errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lfarv committed Jan 12, 2025
1 parent 6c3034b commit 8949b49
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyat/at/latticetools/observablelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __getitem__(self, item):
else:
val = super().__getitem__(item)
if isinstance(val, Exception):
raise AtError(f"Evaluation failed: {val.args[0]}") from val
raise type(val)(val.args[0]) from val
return val

def __iter__(self):
Expand Down
8 changes: 3 additions & 5 deletions pyat/at/latticetools/observables.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,9 @@ def evaluate(self, *data, initial: bool = False):
"""
for d in data:
if isinstance(d, Exception):
errtype = type(d)
err = errtype(f"Evaluation of {self.name} failed: {d.args[0]}")
err.__cause__ = d
message = f"Evaluation of {self.name} failed: {d.args[0]}"
err = type(d)(message).with_traceback(d.__traceback__)
self._value = err
self._shape = None
return err

val = np.asarray(self.fun(*data, *self.args, **self.kwargs))
Expand All @@ -360,7 +358,7 @@ def value(self):
"""Value of the observable."""
val = self._value
if isinstance(val, Exception):
raise val
raise type(val)(val.args[0]) from val
return val

@property
Expand Down

0 comments on commit 8949b49

Please sign in to comment.