|
17 | 17 | def import_dotted_path(dotted_path: str) -> Any: |
18 | 18 | """Imports a dotted path and returns the callable.""" |
19 | 19 | if "." not in dotted_path: |
20 | | - raise ValueError(f"{dotted_path!r} is not a valid dotted path.") |
| 20 | + raise ValueError(f'"{dotted_path}" is not a valid dotted path.') |
21 | 21 |
|
22 | 22 | module_name, component_name = dotted_path.rsplit(".", 1) |
23 | 23 |
|
24 | 24 | try: |
25 | 25 | module = import_module(module_name) |
26 | 26 | except ImportError as error: |
27 | | - msg = f"Failed to import {module_name!r} while loading {component_name!r}" |
28 | | - raise RuntimeError(msg) from error |
| 27 | + msg = f'ReactPy failed to import "{module_name}"' |
| 28 | + raise ImportError(msg) from error |
29 | 29 |
|
30 | | - return getattr(module, component_name) |
| 30 | + try: |
| 31 | + return getattr(module, component_name) |
| 32 | + except AttributeError as error: |
| 33 | + msg = f'ReactPy failed to import "{component_name}" from "{module_name}"' |
| 34 | + raise AttributeError(msg) from error |
31 | 35 |
|
32 | 36 |
|
33 | 37 | def import_components(dotted_paths: Iterable[str]) -> dict[str, Any]: |
@@ -111,4 +115,4 @@ def process_settings(settings: ReactPyConfig) -> None: |
111 | 115 | if config_object: |
112 | 116 | config_object.set_current(settings[setting]) # type: ignore |
113 | 117 | else: |
114 | | - raise ValueError(f"Unknown ReactPy setting {setting!r}.") |
| 118 | + raise ValueError(f'Unknown ReactPy setting "{setting}".') |
0 commit comments