Skip to content

fix(no-ticket): show API errors whose field errors contain objects - #548

Draft
cloudsmith-iduffy wants to merge 1 commit into
masterfrom
iduffy/fix-error-fields-non-string
Draft

cloudsmith-iduffy wants to merge 1 commit into
masterfrom
iduffy/fix-error-fields-non-string

Conversation

@cloudsmith-iduffy

Copy link
Copy Markdown
Collaborator

Description

When an API error has objects in its fields, the CLI crashes and hides the real error. This happens with DRF error codes such as {"non_field_errors": [{"code": 1}]} and with nested serializer errors such as {"items": [{"name": ["required"]}]}. The renderer joined the values as strings, so it raised TypeError.

This PR adds one small helper in cli/exceptions.py that renders any JSON value as text. Strings stay as they are. Lists are joined with spaces, as before. Objects become key: message pairs. Both get_details and print_error_details use it. A fields value that is not an object is treated as non-field errors.

Before, with {"detail": "bad", "fields": {"non_field_errors": [{"code": 1}]}}:

$ cloudsmith status o/r/p
Getting status of p in o/r ... Error: TypeError: sequence item 0: expected str instance, dict found

$ cloudsmith status o/r/p -F json
Getting status of p in o/r ... Error: TypeError: sequence item 0: expected str instance, dict found

After:

$ cloudsmith status o/r/p
Getting status of p in o/r ... ERROR
Failed to get status of package! (status: 400 - Bad Request)

Detail: bad code: 1

$ cloudsmith status o/r/p -F json
{"detail": "bad code: 1", "help": {"context": "Failed to get status of package!", "hint": null}, "meta": {"code": 400, "description": "Bad Request"}}

Before, with {"detail": "bad", "fields": {"items": [{"name": ["required"], "price": ["invalid"]}]}}, the text output printed Detail: bad and then the same TypeError. After:

Detail: bad
Items Field: name: required; price: invalid

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactoring
  • Other (please describe)

Additional Notes

  • The JSON fields object is unchanged. Nested field errors keep their structure there. Only the text output and the JSON detail string use the new rendering.
  • Output for lists of strings is the same as before.
  • I tested this against a local mock server that returns these 400 bodies, and with new tests in test_exceptions.py.
  • fix(no-ticket): show the API error when the error body is not a JSON object #526 changes core/api/exceptions.py. This PR changes only cli/exceptions.py, so the two do not conflict.

🤖 Generated with Claude Code

The error renderer joined field errors as strings. An API error with objects in its fields, such as DRF non_field_errors codes or nested serializer errors, stopped the CLI with a TypeError and hid the API error.

Render each JSON error value as readable text in one helper. Lists of strings render as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 24, 2026 17:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused rendering changes address the reported crashes, include regression coverage, and have no identified blocking issues.

No open issues 🎉

What changed in this PR

Fixes CLI crashes when API field errors contain objects or nested values, complementing #526’s handling of non-object error bodies.

Changes:

  • Adds recursive text rendering for nested error values while preserving structured JSON field output.
  • Adds regression tests for nested fields, object details, and non-object fields.
  • Documents the fix in the changelog.
File Description
cloudsmith_cli/​cli/​tests/​test_exceptions.py Adds text and JSON error-rendering regression tests.
cloudsmith_cli/​cli/​exceptions.py Renders nested error values and normalizes non-object fields.
CHANGELOG.md Documents the field-error rendering fix.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants