Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lando_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,14 @@ def post_actions(

try:
response_json = result.json()
click.echo(response_json["details"])
# Bug 2059648: check the desired property,
# but fall back to the deprecated one.
click.echo(
response_json.get(
"detail",
response_json.get("details", "(missing detail in error response)"),
)
)
except Exception:
click.echo("Unknown error.")

Expand Down
30 changes: 30 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import Callable
import pytest
from pathlib import Path
import requests
import requests_mock
import subprocess

from lando_cli.cli import (
Expand All @@ -12,9 +14,15 @@
detect_merge_from_current_head,
determine_base_sha_for_push,
get_current_branch,
post_actions,
)


@pytest.fixture
def config() -> Config:
return Config("token", "https://lando.example.net", "user@example.net", True)


@pytest.mark.parametrize(
"config_content, expected, should_raise",
[
Expand Down Expand Up @@ -230,3 +238,25 @@ def test_determine_base_sha_for_push_with_relbranch_missing(
"branch_name": "FIREFOX_101_RELBRANCH",
"commit_sha": merge_base,
}


@pytest.mark.parametrize("error_key", ("detail", "details", None))
def test_post_actions_error_details(
config: Config, capsys: pytest.CaptureFixture, error_key: str | None
):
with requests_mock.Mocker() as m:
repo_name = "test-repo"
m.post(
f"{config.lando_url}/api/repo/{repo_name}",
json={error_key: "Some error"},
status_code=400,
)
with pytest.raises(requests.HTTPError):
post_actions(config, repo_name, [{}])

outerr = capsys.readouterr()

if error_key:
assert "Some error" in outerr.out
else:
assert "(missing detail in error response)" in outerr.out
Loading