Skip to content

Commit

Permalink
Fix integer indices in error reporting (#1487)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-melnacouzi authored and sfc-gh-jvasquezrojas committed Aug 26, 2024
1 parent ae6de77 commit d22017f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/snowflake/cli/api/project/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand Down

0 comments on commit d22017f

Please sign in to comment.