File tree 2 files changed +14
-3
lines changed
2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -47,8 +47,7 @@ def _decorator(cls):
47
47
nonlocal alias
48
48
49
49
def _func (self , generated_client ):
50
- module = generated_client .import_module (module_name )
51
- return getattr (module , import_name )
50
+ return generated_client .import_symbol (module_name , import_name )
52
51
53
52
alias = alias or import_name
54
53
_func .__name__ = alias
Original file line number Diff line number Diff line change @@ -45,6 +45,17 @@ def import_module(self, module_path: str) -> Any:
45
45
"""Attempt to import a module from the generated code."""
46
46
return importlib .import_module (f"{ self .base_module } { module_path } " )
47
47
48
+ def import_symbol (self , module_path : str , name : str ) -> Any :
49
+ module = self .import_module (module_path )
50
+ try :
51
+ return getattr (module , name )
52
+ except AttributeError :
53
+ existing = ", " .join (name for name in dir (module ) if not name .startswith ("_" ))
54
+ assert False , (
55
+ f"Couldn't find import \" { name } \" in \" { self .base_module } { module_path } \" .\n "
56
+ f"Available imports in that module are: { existing } \n "
57
+ f"Output from generator was: { self .generator_result .stdout } "
58
+ )
48
59
49
60
def _run_command (
50
61
command : str ,
@@ -67,7 +78,8 @@ def _run_command(
67
78
args .extend (extra_args )
68
79
result = runner .invoke (app , args )
69
80
if result .exit_code != 0 and raise_on_error :
70
- raise Exception (result .stdout )
81
+ message = f"{ result .stdout } \n { result .exception } " if result .exception else result .stdout
82
+ raise Exception (message )
71
83
return result
72
84
73
85
You can’t perform that action at this time.
0 commit comments