From d22017f0b475ae42a3e300f2beb1a8663802f626 Mon Sep 17 00:00:00 2001 From: Michel El Nacouzi Date: Mon, 26 Aug 2024 08:26:02 -0400 Subject: [PATCH] Fix integer indices in error reporting (#1487) --- src/snowflake/cli/api/project/errors.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/snowflake/cli/api/project/errors.py b/src/snowflake/cli/api/project/errors.py index e11a283825..3c272821b6 100644 --- a/src/snowflake/cli/api/project/errors.py +++ b/src/snowflake/cli/api/project/errors.py @@ -29,10 +29,25 @@ class SchemaValidationError(ClickException): def __init__(self, error: ValidationError): errors = error.errors() message = f"During evaluation of {error.title} in project definition following errors were encountered:\n" + + def calculate_location(e): + if e["loc"] is None: + return None + + # show numbers as list indexes and strings as dictionary keys. Example: key1[0].key2 + result = "".join( + f"[{item}]" if isinstance(item, int) else f".{item}" + for item in e["loc"] + ) + + # remove leading dot from the string if any: + return result[1:] if result.startswith(".") else result + message += "\n".join( [ self.message_templates.get(e["type"], self.generic_message).format( - **e, location=".".join(e["loc"]) if e["loc"] is not None else None + **e, + location=calculate_location(e), ) for e in errors ]