Skip to content

Commit

Permalink
Update run in main.py to handle case when port is not int
Browse files Browse the repository at this point in the history
when port is passed as string it will try converting to integer

Then it checks if the port is int and raises ValueError when port is not integer
  • Loading branch information
shashstormer authored Dec 13, 2024
1 parent bfa754e commit 5dd4c03
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion uvicorn/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,13 @@ def run(
) -> None:
if app_dir is not None:
sys.path.insert(0, app_dir)

if isinstance(port, str):
try:
port = int(port)
except ValueError:
pass # The next check ensures port is int and not any other type like dict, str etc.
if not isinstance(port, int):
raise ValueError("Port Must Be a valid interger")
config = Config(
app,
host=host,
Expand Down

0 comments on commit 5dd4c03

Please sign in to comment.