Skip to content

Commit bad671f

Browse files
committed
🐛 Fix deploy command error handling
1 parent cd2e0ba commit bad671f

2 files changed

Lines changed: 25 additions & 23 deletions

File tree

src/fastapi_cloud_cli/commands/deploy.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,10 @@ def _wait_for_deployment(
349349

350350
last_message_changed_at = time.monotonic()
351351

352-
with toolkit.progress(
353-
next(messages), inline_logs=True, lines_to_show=20
354-
) as progress, APIClient() as client:
355-
try:
352+
try:
353+
with toolkit.progress(
354+
next(messages), inline_logs=True, lines_to_show=20
355+
) as progress, APIClient() as client:
356356
for log in client.stream_build_logs(deployment.id):
357357
time_elapsed = time.monotonic() - started_at
358358

@@ -388,13 +388,13 @@ def _wait_for_deployment(
388388

389389
last_message_changed_at = time.monotonic()
390390

391-
except (BuildLogError, TooManyRetriesError) as e:
392-
logger.error("Build log streaming failed: %s", e)
393-
toolkit.print_line()
394-
toolkit.print(
395-
f"⚠️ Unable to stream build logs. Check the dashboard for status: [link={deployment.dashboard_url}]{deployment.dashboard_url}[/link]"
396-
)
397-
raise typer.Exit(1) from e
391+
except (BuildLogError, TooManyRetriesError, TimeoutError) as e:
392+
logger.error("Build log streaming failed: %s", e)
393+
toolkit.print_line()
394+
toolkit.print(
395+
f"⚠️ Unable to stream build logs. Check the dashboard for status: [link={deployment.dashboard_url}]{deployment.dashboard_url}[/link]"
396+
)
397+
raise typer.Exit(1) from e
398398

399399

400400
class SignupToWaitingList(BaseModel):

tests/test_cli_deploy.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from fastapi_cloud_cli.cli import app
1717
from fastapi_cloud_cli.config import Settings
18+
from fastapi_cloud_cli.utils.api import BuildLogError, TooManyRetriesError
1819
from tests.conftest import ConfiguredApp
1920
from tests.utils import Keys, build_logs_response, changing_dir
2021

@@ -771,11 +772,14 @@ def test_shows_no_apps_found_message_when_team_has_no_apps(
771772
)
772773

773774

775+
@pytest.mark.parametrize(
776+
"error",
777+
[BuildLogError, TooManyRetriesError, TimeoutError],
778+
)
774779
@pytest.mark.respx(base_url=settings.base_api_url)
775-
def test_handles_build_log_streaming_error(
776-
logged_in_cli: None, tmp_path: Path, respx_mock: respx.MockRouter
780+
def test_shows_error_message_on_build_exception(
781+
logged_in_cli: None, tmp_path: Path, respx_mock: respx.MockRouter, error: Exception
777782
) -> None:
778-
"""Test that BuildLogError is caught and shows dashboard link (lines 384, 387-392)."""
779783
app_data = _get_random_app()
780784
team_data = _get_random_team()
781785
app_id = app_data["id"]
@@ -802,11 +806,10 @@ def test_handles_build_log_streaming_error(
802806
return_value=Response(200)
803807
)
804808

805-
respx_mock.get(f"/deployments/{deployment_data['id']}/build-logs").mock(
806-
return_value=Response(422, text="Error")
807-
)
808-
809-
with changing_dir(tmp_path):
809+
with changing_dir(tmp_path), patch(
810+
"fastapi_cloud_cli.utils.api.APIClient.stream_build_logs",
811+
side_effect=error,
812+
):
810813
result = runner.invoke(app, ["deploy"])
811814

812815
assert result.exit_code == 1
@@ -815,10 +818,8 @@ def test_handles_build_log_streaming_error(
815818

816819

817820
@pytest.mark.respx(base_url=settings.base_api_url)
818-
def test_shows_error_message_when_build_log_streaming_fails(
819-
logged_in_cli: None,
820-
tmp_path: Path,
821-
respx_mock: respx.MockRouter,
821+
def test_shows_error_message_on_build_log_http_error(
822+
logged_in_cli: None, tmp_path: Path, respx_mock: respx.MockRouter
822823
) -> None:
823824
app_data = _get_random_app()
824825
team_data = _get_random_team()
@@ -853,6 +854,7 @@ def test_shows_error_message_when_build_log_streaming_fails(
853854
with changing_dir(tmp_path), patch("time.sleep"):
854855
result = runner.invoke(app, ["deploy"])
855856

857+
assert result.exit_code == 1
856858
assert "Unable to stream build logs" in result.output
857859
assert deployment_data["dashboard_url"] in result.output
858860

0 commit comments

Comments
 (0)