Skip to content

feat(assemble): Improve error messages for assemble endpoint #88905

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

Merged
merged 6 commits into from
Apr 8, 2025
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
16 changes: 15 additions & 1 deletion src/sentry/api/endpoints/organization_artifactbundle_assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,25 @@ def post(self, request: Request, organization) -> Response:
"additionalProperties": False,
}

error_messages = {
"version": 'The version field cannot be empty and cannot contain any "/" characters.',
"dist": "The dist field must be a string.",
"projects": "The projects field is required and must be provided as an array of strings.",
"checksum": "The checksum field is required and must be a 40-character hexadecimal string.",
"chunks": "The chunks field is required and must be provided as an array of 40-character hexadecimal strings.",
}

try:
data = orjson.loads(request.body)
jsonschema.validate(data, schema)
except jsonschema.ValidationError as e:
return Response({"error": str(e).splitlines()[0]}, status=400)
error_message = e.message
# Get the field from the path if available
if e.path:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field contains a queue of the fields inside the schema that are matched.

if field := e.path[0]:
error_message = error_messages.get(str(field), error_message)

return Response({"error": error_message}, status=400)
except Exception:
return Response({"error": "Invalid json body"}, status=400)

Expand Down
Loading