Commit a759ba3
Cipher
fix: handle OptionalImportError for class-based reader instantiation
The exception handling for missing optional packages only wrapped string-based
reader imports (LoadImage(reader='ITKReader')). When users passed a class directly
(LoadImage(reader=ITKReader)), OptionalImportError would leak through.
Update the class instantiation path (elif inspect.isclass(_r):) to:
1. Catch OptionalImportError during _r(*args, **kwargs) call
2. Re-raise as RuntimeError with consistent message
3. Use exception chaining (from e) for debugging
4. Handle TypeError with warn-and-retry (same as string path)
5. Extract class name safely for error message
Now both LoadImage(reader='ITKReader') and LoadImage(reader=ITKReader) produce
consistent RuntimeError when the optional package is missing.
Add test_explicit_class_reader_not_installed_raises_runtime_error to verify
the class path is properly handled.
Signed-off-by: Cipher <cipher@openclaw.ai>1 parent 13a87bd commit a759ba3
2 files changed
Lines changed: 21 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
222 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
223 | 234 | | |
224 | 235 | | |
225 | 236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
514 | 514 | | |
515 | 515 | | |
516 | 516 | | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
517 | 526 | | |
518 | 527 | | |
519 | 528 | | |
| |||
0 commit comments