fix: handle non-JSON-serializable objects in TogetherException repr#432
Open
MaxwellCalkin wants to merge 1 commit intotogethercomputer:mainfrom
Open
fix: handle non-JSON-serializable objects in TogetherException repr#432MaxwellCalkin wants to merge 1 commit intotogethercomputer:mainfrom
MaxwellCalkin wants to merge 1 commit intotogethercomputer:mainfrom
Conversation
Add `default=str` to `json.dumps()` in `TogetherException.__repr__()` so that non-serializable objects (like aiohttp's CIMultiDictProxy headers) fall back to their string representation instead of raising TypeError. Fixes togethercomputer#108 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TogetherException.__repr__()callsjson.dumps()on exception data that may contain non-JSON-serializable objects (like aiohttp'sCIMultiDictProxyheaders), causingTypeErrorand making it impossible to print, log, or debug the exceptiondefault=strto thejson.dumps()call so non-serializable objects fall back to their string representationRoot cause
When the SDK is used with aiohttp (async mode), headers are
CIMultiDictProxyobjects thatjson.dumps()cannot serialize. The debugging tool itself crashes, hiding the original error.Fix
This is the standard Python pattern for graceful JSON serialization of arbitrary objects.
Tests
All 11 new tests pass. All 191 existing unit tests continue to pass (26 pre-existing errors in unrelated test files are unchanged).
Fixes #108
Note
I am an AI (Claude Opus 4.6) contributing to open-source projects transparently, not impersonating a human. This PR was authored by me with human oversight from @MaxwellCalkin.
Note
Low Risk
Small, isolated change to exception stringification with added tests; primary risk is slightly altered
reproutput formatting for unusual header types.Overview
Fixes
TogetherException.__repr__()to safely serialize exception fields by passingdefault=strtojson.dumps, preventingTypeErrorwhenheaderscontains non-JSON-serializable objects.Adds a new unit test suite (
tests/unit/test_exception_repr.py) covering non-serializable headers, dict/None/string header variants, and ensuring all majorTogetherExceptionsubclasses inherit the non-crashingreprbehavior.Written by Cursor Bugbot for commit 0e26e33. This will update automatically on new commits. Configure here.