Skip to content

Commit

Permalink
fix: add documentation links to remote build and esm base errors
Browse files Browse the repository at this point in the history
Signed-off-by: Callahan Kovacs <callahan.kovacs@canonical.com>
  • Loading branch information
mr-cal committed Sep 20, 2024
1 parent 8b6cda1 commit 9caf772
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
4 changes: 4 additions & 0 deletions snapcraft/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def _get_esm_error_for_base(base: str) -> None:
f"Use Snapcraft {version} from the {channel!r} channel of snapcraft where "
f"{base!r} was last supported."
),
doc_slug="/reference/bases",
)


Expand Down Expand Up @@ -395,6 +396,7 @@ def _ensure_remote_build_supported(base: str) -> None:
resolution=(
"Valid values are 'disable-fallback' and 'force-fallback'."
),
doc_slug="/explanation/remote-build",
)

# 2. core20 projects must use the legacy remote builder (#4885)
Expand All @@ -407,6 +409,7 @@ def _ensure_remote_build_supported(base: str) -> None:
resolution=(
"Unset the environment variable or set it to 'force-fallback'."
),
doc_slug="/explanation/remote-build",
)

# 3. core24 and newer projects must use the craft-application remote builder
Expand All @@ -419,6 +422,7 @@ def _ensure_remote_build_supported(base: str) -> None:
resolution=(
"Unset the environment variable or set it to 'disable-fallback'."
),
doc_slug="/explanation/remote-build",
)

@override
Expand Down
34 changes: 23 additions & 11 deletions tests/unit/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,13 @@ def test_esm_error(snapcraft_yaml, base, monkeypatch, capsys):
application.main()

_, err = capsys.readouterr()
assert f"Base {base!r} is not supported by this version of Snapcraft" in err

assert re.match(
rf"^Base {base!r} is not supported by this version of Snapcraft.\n"
rf"Recommended resolution: Use Snapcraft .* from the '.*' channel of snapcraft where {base!r} was last supported.\n"
r"For more information, check out: .*/reference/bases\n",
err,
)


@pytest.mark.parametrize("base", const.CURRENT_BASES)
Expand Down Expand Up @@ -461,10 +467,12 @@ def test_run_remote_build_core24_error(monkeypatch, snapcraft_yaml, base, capsys
application.main()

_, err = capsys.readouterr()
assert (
"'SNAPCRAFT_REMOTE_BUILD_STRATEGY=force-fallback' cannot be used "
"for core24 and newer snaps"
) in err
assert re.match(
r"^'SNAPCRAFT_REMOTE_BUILD_STRATEGY=force-fallback' cannot be used for core24 and newer snaps\.\n"
r"Recommended resolution: Unset the environment variable or set it to 'disable-fallback'\.\n"
r"For more information, check out: .*/explanation/remote-build",
err,
)


@pytest.mark.parametrize("base", const.LEGACY_BASES)
Expand All @@ -479,9 +487,11 @@ def test_run_envvar_disable_fallback_core20(snapcraft_yaml, base, monkeypatch, c
application.main()

_, err = capsys.readouterr()
assert (
f"'SNAPCRAFT_REMOTE_BUILD_STRATEGY=disable-fallback' cannot be used for {base} snaps"
in err
assert re.match(
r"'SNAPCRAFT_REMOTE_BUILD_STRATEGY=disable-fallback' cannot be used for core20 snaps\.\n"
r"Recommended resolution: Unset the environment variable or set it to 'force-fallback'\.\n"
r"For more information, check out: .*/explanation/remote-build",
err,
)


Expand Down Expand Up @@ -546,9 +556,11 @@ def test_run_envvar_invalid(snapcraft_yaml, base, monkeypatch, capsys):
application.main()

_, err = capsys.readouterr()
assert (
"Unknown value 'badvalue' in environment variable 'SNAPCRAFT_REMOTE_BUILD_STRATEGY'"
in err
assert re.match(
r"Unknown value 'badvalue' in environment variable 'SNAPCRAFT_REMOTE_BUILD_STRATEGY'\.\n"
r"Recommended resolution: Valid values are 'disable-fallback' and 'force-fallback'\.\n"
r"For more information, check out: .*/explanation/remote-build",
err,
)


Expand Down

0 comments on commit 9caf772

Please sign in to comment.