Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integer indices in error reporting #1487

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading