diff --git a/src/instructlab/schema/taxonomy.py b/src/instructlab/schema/taxonomy.py index 9e2f9c7..fe927ac 100644 --- a/src/instructlab/schema/taxonomy.py +++ b/src/instructlab/schema/taxonomy.py @@ -429,6 +429,6 @@ def parse(self, path: str | pathlib.Path) -> Taxonomy: self._schema_validate(text=text, taxonomy=taxonomy) except Exception as e: - raise TaxonomyReadingException from e + raise TaxonomyReadingException(str(e)) from e return taxonomy diff --git a/tests/test_parse.py b/tests/test_parse.py index b1b39a3..1d64946 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -34,6 +34,22 @@ def test_parser_init_fails_when_schema_version_not_found(self, mock_schema_versi assert_that(str(exc_info.value)).matches(r'Schema base ".*" does not contain any schema versions') +class TestTaxonomyReadingExceptionDisplay: + def test_invalid_yaml_with_taxonomy_reading_exception(self, testdata: pathlib.Path) -> None: + test_yaml = "compositional_skills/invalid_yaml_1/qna.yaml" + rel_path = testdata.joinpath(test_yaml) + parser = TaxonomyParser(schema_version=2) + + with pytest.raises(TaxonomyReadingException) as exc_info: + parser.parse(rel_path) + + exception = exc_info.value + assert_that(exception).is_instance_of(TaxonomyReadingException) + assert_that(str(exception)).contains("while scanning a simple key") + assert_that(str(exception)).contains("seed_examples:xx") + assert_that(str(exception.__cause__)).contains("could not find expected ':'") + + class TestParsingLogging: def message_filter(self, regex: str) -> Callable[[logging.LogRecord], bool]: pattern = re.compile(regex) diff --git a/tests/testdata/compositional_skills/invalid_yaml_1/qna.yaml b/tests/testdata/compositional_skills/invalid_yaml_1/qna.yaml new file mode 100644 index 0000000..97abdde --- /dev/null +++ b/tests/testdata/compositional_skills/invalid_yaml_1/qna.yaml @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: Apache-2.0 + +createdby: invalid_key_1 +version: 2 +seed_examples:xx +- question: What is this skill about? + answer: It's a skill that makes the tests more skillful +- answer: "answer2" + question: "question2" +- answer: "answer6" + question: "This is for a unit test and has a line with 124 characters! It is too long for the default rules but not too long for the customer rules!" +- answer: "answer3" + question: "question3" +- answer: "answer4" + question: "question4" +- answer: "answer5" + question: "question5" +task_description: For TaxonomyReadingException test