exceptions: call super().__init__() in APIError#1040
Open
prashantbytesyntax wants to merge 1 commit into
Open
Conversation
`APIError.__init__` previously skipped `super().__init__()`, leaving the base `Exception` machinery uninitialized — most notably `self.args`, which breaks `repr(e)`, pickling, and any code that inspects `e.args`. Forward `message` to `super().__init__(message)` so the standard Exception state is populated. Also tighten the `full_data` annotation from `dict = None` to `Optional[Dict[str, Any]]` so it actually matches the default value and the data being passed (a JSON response dict). No behavior change for existing call sites in `client.py`; this just makes the exception behave correctly when introspected. Co-authored-by: Cursor <cursoragent@cursor.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
APIError.__init__never callssuper().__init__(), so the baseExceptionmachinery is left uninitialized — most importantlyself.args, which breaksrepr(e), pickling, and any code that inspectse.args(including some logging configurations andmultiprocessingpropagation).This PR:
messagetosuper().__init__(message)so the standardExceptionstate is populated.full_dataparameter annotation fromdict = NonetoOptional[Dict[str, Any]]so it actually matches the default value and what the call sites pass (a parsed JSON response dict, seegprofiler/client.py).No behavior change for the existing call sites in
client.py—str(e)still returnsself.message, ande.full_datais unchanged. The only observable difference is thate.argsis now populated andrepr(e)works as expected.Before / after
Test plan
./tests/test.sh)./lint.shis cleanAPIError("msg")/APIError("msg", {"k": 1})and confirmstr(e),repr(e), ande.full_databehave as expectedMade with Cursor