Skip to content

Commit

Permalink
Merge pull request #119 from mobiusml/endpoint_invalid_types
Browse files Browse the repository at this point in the history
Improve Error Handling for Invalid Argument Types in API Generation
  • Loading branch information
movchan74 authored Jun 21, 2024
2 parents d3a1010 + 95d144b commit 4ebcfd9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions aana/api/api_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ def arg_to_field(self, arg_name: str, arg_type: Any) -> tuple[Any, Any]:
# to see if any of the fields are required
try:
data_model_instance = arg_type()
except TypeError as e:
raise ValueError( # noqa: TRY003
f"Invalid type for argument {arg_name}: {arg_type}. "
"Consider using Annotated[..., Field(...)] or Pydantic models."
) from e
except ValidationError:
# if we can't instantiate the data model
# it means that it has required fields
Expand Down
2 changes: 1 addition & 1 deletion aana/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def deploy(self, blocking: bool = False):
serve.shutdown()
sys.exit()
except RuntimeError:
self.show_status("RequestHandler")
self.show_status(self.name)
except Exception:
traceback.print_exc()
print(
Expand Down

0 comments on commit 4ebcfd9

Please sign in to comment.