Skip to content

Commit

Permalink
fix: add recovery instructions to remote timeout error
Browse files Browse the repository at this point in the history
Signed-off-by: Callahan Kovacs <[email protected]>
  • Loading branch information
mr-cal committed Oct 27, 2023
1 parent 1751cc8 commit 3484a1e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
10 changes: 7 additions & 3 deletions snapcraft/remote/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ def __init__(self, message: str) -> None:
class RemoteBuildTimeoutError(RemoteBuildError):
"""Remote-build timed out."""

def __init__(self) -> None:
brief = "Remote build timed out."
def __init__(self, recovery_command: str) -> None:
brief = "Remote build command timed out."
details = (
"Build may still be running on Launchpad and can be recovered "
f"with {recovery_command!r}."
)

super().__init__(brief=brief)
super().__init__(brief=brief, details=details)


class LaunchpadHttpsError(RemoteBuildError):
Expand Down
6 changes: 5 additions & 1 deletion snapcraft/remote/launchpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ def _check_timeout_deadline(self) -> None:
return

if int(time.time()) >= self._deadline:
raise errors.RemoteBuildTimeoutError()
raise errors.RemoteBuildTimeoutError(
recovery_command=(
f"{self._app_name} remote-build --recover --build-id {self._build_id}"
)
)

def _create_data_directory(self) -> Path:
data_dir = Path(
Expand Down
22 changes: 16 additions & 6 deletions tests/unit/remote/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,24 @@ def test_git_error():

def test_remote_build_timeout_error():
"""Test RemoteBuildTimeoutError."""
error = errors.RemoteBuildTimeoutError()
error = errors.RemoteBuildTimeoutError(
recovery_command="craftapp remote-build --recover --build-id test-id"
)

assert str(error) == "Remote build timed out."
assert (
repr(error)
== "RemoteBuildTimeoutError(brief='Remote build timed out.', details=None)"
assert str(error) == (
"Remote build command timed out.\nBuild may still be running on Launchpad and "
"can be recovered with 'craftapp remote-build --recover --build-id test-id'."
)
assert repr(error) == (
"RemoteBuildTimeoutError(brief='Remote build command timed out.', "
'details="Build may still be running on Launchpad and can be recovered with '
"'craftapp remote-build --recover --build-id test-id'.\")"
)
assert error.brief == "Remote build command timed out."
assert error.details == (
"Build may still be running on Launchpad and can be recovered with "
"'craftapp remote-build --recover --build-id test-id'."
)
assert error.brief == "Remote build timed out."


def test_launchpad_https_error():
Expand Down
10 changes: 8 additions & 2 deletions tests/unit/remote/test_launchpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,10 @@ def test_start_build_timeout_error(mock_login_with, mocker):
with pytest.raises(errors.RemoteBuildTimeoutError) as raised:
lpc.start_build()

assert str(raised.value) == "Remote build timed out."
assert str(raised.value) == (
"Remote build command timed out.\nBuild may still be running on Launchpad and "
"can be recovered with 'test-app remote-build --recover --build-id id'."
)


def test_issue_build_request_defaults(launchpad_client):
Expand Down Expand Up @@ -490,7 +493,10 @@ def test_monitor_build_timeout_error(mock_login_with, mocker):
with pytest.raises(errors.RemoteBuildTimeoutError) as raised:
lpc.monitor_build(interval=0)

assert str(raised.value) == "Remote build timed out."
assert str(raised.value) == (
"Remote build command timed out.\nBuild may still be running on Launchpad and "
"can be recovered with 'test-app remote-build --recover --build-id id'."
)


def test_get_build_status(launchpad_client):
Expand Down

0 comments on commit 3484a1e

Please sign in to comment.