Skip to content

Commit

Permalink
Add special case for "class" in exc string
Browse files Browse the repository at this point in the history
  • Loading branch information
elevans committed Jan 14, 2025
1 parent 7f26813 commit 2b947aa
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/imagej/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,19 @@ def _format_copy_exception(exc: str, fun_name: str) -> str:
"""
# format cast exception
exc = str(exc)
m = exc.split(" ")
if "cannot be cast to" in exc:
m = exc.split(" ")
from_class = m[m.index("cannot") - 1]
to_class = m[m.index("cast") + 3]
return f"Error: Unsupported type cast via {fun_name}\n Source type: {from_class}\n Target type: {to_class}"
# special case if "class" is present or not
ci = m.index("cast")
if m[ci + 2] == "class":
to_class = m[ci + 3]
else:
to_class = m[ci + 2]
return (
f"Error: Unsupported type cast via {fun_name}\n"
f" Source type: {from_class}\n"
f" Target type: {to_class}"
)
else:
return exc

0 comments on commit 2b947aa

Please sign in to comment.