Skip to content

Commit

Permalink
Replace sys.exit in _get_contents
Browse files Browse the repository at this point in the history
  • Loading branch information
kenodegard committed May 20, 2024
1 parent e112c64 commit 5cb28a2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions conda_build/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1965,8 +1965,8 @@ def _get_contents(
except jinja2.TemplateError as ex:
if "'None' has not attribute" in str(ex):
ex = "Failed to run jinja context function"
sys.exit(
f"Error: Failed to render jinja template in {self.meta_path}:\n{str(ex)}"
raise CondaBuildUserError(
f"Failed to render jinja template in {self.meta_path}:\n{str(ex)}"
)
finally:
if "CONDA_BUILD_STATE" in os.environ:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
from .utils import metadata_dir, metadata_path, thisdir

if TYPE_CHECKING:
from pathlib import Path

from pytest import MonkeyPatch


Expand Down Expand Up @@ -607,3 +609,18 @@ def test_check_bad_chrs(value: str, field: str, invalid: str) -> None:
match=rf"Bad character\(s\) \({invalid}\) in {field}: {value}\.",
) if invalid else nullcontext():
check_bad_chrs(value, field)


def test_parse_until_resolved(testing_metadata: MetaData, tmp_path: Path) -> None:
(recipe := tmp_path / (name := "meta.yaml")).write_text("{{ UNDEFINED[:2] }}")
testing_metadata._meta_path = recipe
testing_metadata._meta_name = name

with pytest.raises(
CondaBuildUserError,
match=(
rf"Failed to render jinja template in {recipe}:\n"
r"'UNDEFINED' is undefined"
),
):
testing_metadata.parse_until_resolved()

0 comments on commit 5cb28a2

Please sign in to comment.