From d013bd22dcd4736927c1f35213e9364fdec43e09 Mon Sep 17 00:00:00 2001 From: Radoslaw Smigielski Date: Sun, 15 Dec 2024 19:13:20 +0100 Subject: [PATCH] Separate CalledProcessError and FileNotFoundError exceptions Orginal logic does not make distinction between situation when: 1. yq is missing, not installed, this problem is addressed here: https://github.com/instructlab/instructlab/pull/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 --- src/instructlab/schema/taxonomy.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/instructlab/schema/taxonomy.py b/src/instructlab/schema/taxonomy.py index a3e9e14..fd8d3bb 100644 --- a/src/instructlab/schema/taxonomy.py +++ b/src/instructlab/schema/taxonomy.py @@ -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":