Skip to content

Commit

Permalink
Separate CalledProcessError and FileNotFoundError exceptions
Browse files Browse the repository at this point in the history
Orginal logic does not make distinction between situation when:
 1. yq is missing, not installed, this problem is addressed here:
    instructlab/instructlab#2796
 2. when yq found a problem with the format and validation
    command failed

This commit separate scenario [1] and [2]. Also improve warning
messages, allows user to re-run the yq command and help find a problem
within qna.yaml file.

Signed-off-by: Radoslaw Smigielski <[email protected]>
  • Loading branch information
radeksm committed Dec 15, 2024
1 parent a5c7979 commit d013bd2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/instructlab/schema/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,15 @@ def _schema_validate(self, text: str, taxonomy: Taxonomy) -> None:
yq_expression = f"{yaml_path} | line"
line = subprocess.check_output(["yq", yq_expression], input=text, text=True)
line = line.strip() if line else 1
except (subprocess.CalledProcessError, FileNotFoundError) as e:
if isinstance(e, FileNotFoundError):
self.yq_available = False
except subprocess.CalledProcessError as e_yq:
logger.warning(
"could not run yq command",
f"Failed to validate file {taxonomy.path}, error: {e_yq}\n"
f"Failed command: yq \"{yq_expression}\" {taxonomy.path}"
)
except FileNotFoundError as e:
self.yq_available = False
logger.warning(
"Missing yq command, could not run yq command",
exc_info=True,
)
if validation_error.validator == "minItems":
Expand Down

0 comments on commit d013bd2

Please sign in to comment.