Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 17, 2025

  • Analyze the issue: JsonDecodeError stores response content but doesn't show it in the error message
  • Update JsonDecodeError.init to include content in the message when available
  • Update tests to verify the fix works correctly
  • Test the fix with manual verification script
  • Run linting to ensure code follows project style
  • Verify all tests pass with no regressions
  • Add changelog entry for issue bug: JsonDecodeError should show actual content #473

Changes Made:

  1. Fixed JsonDecodeError in infrahub_sdk/exceptions.py: Modified the __init__ method to append server response content to the default error message when available. This provides better debugging information when servers return non-JSON error responses.

  2. Added comprehensive tests in tests/unit/sdk/test_utils.py: Added 4 new test cases to verify:

    • decode_json works correctly with valid JSON
    • decode_json includes server content in error messages when available
    • decode_json handles empty content gracefully
    • Custom error messages are preserved when provided
  3. Added changelog entry: Created changelog/473.fixed.md documenting the fix.

The Fix:
The issue was that when servers return error responses that aren't JSON formatted (like HTML error pages or plain text error messages), users only saw a generic message like "Unable to decode response as JSON data from {url}" without the actual server error. Now they see the actual error content, making debugging much easier.

Before: Unable to decode response as JSON data from https://example.com/graphql
After: Unable to decode response as JSON data from https://example.com/graphql. Server response: Internal Server Error: Database connection failed

This fix is minimal and backward-compatible - it only affects the default error message generation when no custom message is provided.

Fixes #473.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Sep 17, 2025

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7858a62
Status: ✅  Deploy successful!
Preview URL: https://de988df4.infrahub-sdk-python.pages.dev
Branch Preview URL: https://copilot-fix-473.infrahub-sdk-python.pages.dev

View logs

@opsmill opsmill deleted a comment from Copilot AI Sep 17, 2025
Copilot AI changed the title [WIP] bug: JsonDecodeError should show actual content Fix JsonDecodeError to include server response content in error message Sep 17, 2025
Copilot AI requested a review from BeArchiTek September 17, 2025 15:00
Copilot finished work on behalf of BeArchiTek September 17, 2025 15:00
@codecov
Copy link

codecov bot commented Sep 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##           stable     #553      +/-   ##
==========================================
+ Coverage   75.59%   75.69%   +0.09%     
==========================================
  Files         100      100              
  Lines        8892     8894       +2     
  Branches     1750     1751       +1     
==========================================
+ Hits         6722     6732      +10     
+ Misses       1688     1680       -8     
  Partials      482      482              
Flag Coverage Δ
integration-tests 34.68% <0.00%> (+<0.01%) ⬆️
python-3.10 48.21% <100.00%> (+0.07%) ⬆️
python-3.11 48.23% <100.00%> (+0.10%) ⬆️
python-3.12 48.18% <100.00%> (+0.10%) ⬆️
python-3.13 48.21% <100.00%> (+0.12%) ⬆️
python-3.9 46.85% <100.00%> (+0.10%) ⬆️
python-filler-3.12 24.99% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/exceptions.py 87.50% <100.00%> (+5.68%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@fatih-acar fatih-acar left a comment

Choose a reason for hiding this comment

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

Thank you @copilot (not you @BeArchiTek 😆)

@BeArchiTek BeArchiTek added the type/bug Something isn't working as expected label Sep 30, 2025
@BeArchiTek BeArchiTek marked this pull request as ready for review September 30, 2025 09:15
@coderabbitai
Copy link

coderabbitai bot commented Sep 30, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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

@BeArchiTek
Copy link
Contributor

BeArchiTek commented Sep 30, 2025

@copilot add the changelog file with the issue reference

Copy link
Contributor Author

Copilot AI commented Sep 30, 2025

@copilot add the changelog file with the issue reference

Added changelog entry in changelog/473.fixed.md referencing issue #473. Commit: 85a7c1f

Copilot finished work on behalf of BeArchiTek September 30, 2025 09:21
@BeArchiTek BeArchiTek merged commit 1c94694 into stable Sep 30, 2025
1 check passed
@BeArchiTek BeArchiTek deleted the copilot/fix-473 branch September 30, 2025 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: JsonDecodeError should show actual content

3 participants