Skip to content

fix: error response cleansing#51

Merged
Prashant-Surya merged 1 commit into
mainfrom
fix-error-detail-transmit
Jun 15, 2026
Merged

fix: error response cleansing#51
Prashant-Surya merged 1 commit into
mainfrom
fix-error-detail-transmit

Conversation

@sunder-ch

@sunder-ch sunder-ch commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Description

Surface API error details (field-level validation, detail/error keys) in HttpError.__str__ and tracebacks instead of suppressing them behind a generic HTTP 400: Bad Request message.

Summary by CodeRabbit

  • Refactor

    • Enhanced error handling with improved serialization support and richer exception metadata.
    • Error messages now include additional context and details from API responses for better diagnostics.
  • Tests

    • Added comprehensive test coverage for error handling across various response formats and edge cases.

@sunder-ch sunder-ch requested a review from dheeru0198 June 11, 2026 16:33
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds error serialization support and payload normalization to the error-handling module. A new _extract_detail() helper converts heterogeneous API error responses (strings, dicts with detail/error/message keys, field-level errors, lists) into a single detail string. Both PlaneError and HttpError gain __reduce__() for pickling, while HttpError also gains __str__() and __repr__() methods that surface extracted details in string representations and exception tracebacks.

Changes

Error handling and serialization enhancements

Layer / File(s) Summary
Test module setup
tests/unit/test_errors.py
Module-level documentation and imports are established for the error test suite.
Detail extraction helper and unit tests
plane/errors/errors.py, tests/unit/test_errors.py
_extract_detail() function normalizes string, dict, and list error payloads into a single optional detail string, with comprehensive unit tests validating field-level error formatting and precedence rules.
PlaneError pickling support and unit tests
plane/errors/errors.py, tests/unit/test_errors.py
PlaneError.__reduce__() enables pickling/deserialization while preserving exception type, message, and status_code, with unit tests verifying stringification, optional status codes, and exception catchability.
HttpError enrichment with detail surfacing and unit tests
plane/errors/errors.py, tests/unit/test_errors.py
HttpError gains __reduce__() for serialization, __str__() appends extracted detail from response payloads, and __repr__() includes message, status code, and response metadata. Unit tests verify detail surfacing for dict/field-level/plain-text payloads, __repr__ content, attributes, inheritance, and traceback visibility.
Integration and edge-case tests
tests/unit/test_errors.py
Integration tests verify BaseResource._handle_response raises HttpError with full payload and surfaced details across multiple status codes and error shapes; edge-case tests cover response=None, empty payloads, pickling round-trips, and logging usage.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Exception classes now pickle and show,
With detail extraction from payloads below,
HttpError blooms with __str__ and __repr__,
Five hundred tests ensure all errors are fair! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: error response cleansing' directly relates to the main change: improving error response handling by extracting and surfacing API error details instead of suppressing them, making errors more transparent to users.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-error-detail-transmit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/unit/test_errors.py (1)

464-468: 💤 Low value

Redundant status code assignment.

Line 466 sets mock_resp.status_code = 204 but this is already set by _make_mock_response(204, ...) on line 465.

♻️ Suggested fix
     def test_204_returns_none(self, resource: BaseResource) -> None:
         mock_resp = self._make_mock_response(204, "No Content")
-        mock_resp.status_code = 204
         result = resource._handle_response(mock_resp)
         assert result is None
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/test_errors.py` around lines 464 - 468, Remove the redundant
status assignment in test_204_returns_none: the helper _make_mock_response(204,
"No Content") already sets mock_resp.status_code, so delete the explicit
mock_resp.status_code = 204 line in the test (test_204_returns_none) and keep
the call to _make_mock_response and the subsequent _handle_response assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/unit/test_errors.py`:
- Around line 464-468: Remove the redundant status assignment in
test_204_returns_none: the helper _make_mock_response(204, "No Content") already
sets mock_resp.status_code, so delete the explicit mock_resp.status_code = 204
line in the test (test_204_returns_none) and keep the call to
_make_mock_response and the subsequent _handle_response assertion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 01167552-096e-4d63-b5b8-d32c4c0d070b

📥 Commits

Reviewing files that changed from the base of the PR and between 491a923 and 9389d5d.

📒 Files selected for processing (2)
  • plane/errors/errors.py
  • tests/unit/test_errors.py

@Prashant-Surya Prashant-Surya merged commit b23b595 into main Jun 15, 2026
4 checks passed
@Prashant-Surya Prashant-Surya deleted the fix-error-detail-transmit branch June 15, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants