Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit e085ba1

Browse files
authored
Merge pull request #82 from reidliu41/fix-not-display-error
fix the error not display when yaml file is incorrect
2 parents 4738551 + 7e31da6 commit e085ba1

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/instructlab/schema/taxonomy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,6 @@ def parse(self, path: str | pathlib.Path) -> Taxonomy:
429429

430430
self._schema_validate(text=text, taxonomy=taxonomy)
431431
except Exception as e:
432-
raise TaxonomyReadingException from e
432+
raise TaxonomyReadingException(str(e)) from e
433433

434434
return taxonomy

tests/test_parse.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ def test_parser_init_fails_when_schema_version_not_found(self, mock_schema_versi
3434
assert_that(str(exc_info.value)).matches(r'Schema base ".*" does not contain any schema versions')
3535

3636

37+
class TestTaxonomyReadingExceptionDisplay:
38+
def test_invalid_yaml_with_taxonomy_reading_exception(self, testdata: pathlib.Path) -> None:
39+
test_yaml = "compositional_skills/invalid_yaml_1/qna.yaml"
40+
rel_path = testdata.joinpath(test_yaml)
41+
parser = TaxonomyParser(schema_version=2)
42+
43+
with pytest.raises(TaxonomyReadingException) as exc_info:
44+
parser.parse(rel_path)
45+
46+
exception = exc_info.value
47+
assert_that(exception).is_instance_of(TaxonomyReadingException)
48+
assert_that(str(exception)).contains("while scanning a simple key")
49+
assert_that(str(exception)).contains("seed_examples:xx")
50+
assert_that(str(exception.__cause__)).contains("could not find expected ':'")
51+
52+
3753
class TestParsingLogging:
3854
def message_filter(self, regex: str) -> Callable[[logging.LogRecord], bool]:
3955
pattern = re.compile(regex)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
createdby: invalid_key_1
4+
version: 2
5+
seed_examples:xx
6+
- question: What is this skill about?
7+
answer: It's a skill that makes the tests more skillful
8+
- answer: "answer2"
9+
question: "question2"
10+
- answer: "answer6"
11+
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!"
12+
- answer: "answer3"
13+
question: "question3"
14+
- answer: "answer4"
15+
question: "question4"
16+
- answer: "answer5"
17+
question: "question5"
18+
task_description: For TaxonomyReadingException test

0 commit comments

Comments
 (0)