forked from openfga/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Claude/verify error handling state 01 gk msbed e ey9 zlp csvdxib v #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SoulPancake
wants to merge
7
commits into
main
Choose a base branch
from
claude/verify-error-handling-state-01GkMsbedEEy9ZLPCsvdxibV
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Claude/verify error handling state 01 gk msbed e ey9 zlp csvdxib v #9
SoulPancake
wants to merge
7
commits into
main
from
claude/verify-error-handling-state-01GkMsbedEEy9ZLPCsvdxibV
Conversation
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
…methods
This commit significantly improves error handling in the Python SDK by adding:
1. Convenience Properties:
- Direct access to error code via e.code (instead of e.parsed_exception.code)
- Direct access to error message via e.error_message
- Direct access to request ID via e.request_id
- Direct access to store ID via e.store_id
- Direct access to authorization model ID via e.authorization_model_id
2. Operation Context:
- Added operation_name parameter to ApiException and all subclasses
- Exceptions now track which operation failed (e.g., "Check", "Write")
- operation_name propagated through api_client call stack
3. Helper Methods:
- is_validation_error() - Check if error is a validation error
- is_not_found_error() - Check if error is a not found error
- is_authentication_error() - Check if error is an authentication error
- is_authorization_error() - Check if error is an authorization error
- is_rate_limit_error() - Check if error is a rate limit error
- is_server_error() - Check if error is a server error
- is_retryable() - Check if error should be retried
4. Enhanced Error Messages:
- __str__ method now includes operation name, error code, message,
request ID, store ID, and authorization model ID
- More readable and informative error output
5. Testing:
- Added comprehensive unit tests (17 test cases)
- Added integration tests against real OpenFGA server
- Docker Compose setup for integration testing
- Test documentation and run script
Changes are fully backwards compatible - existing code continues to work.
Files modified:
- openfga_sdk/exceptions.py: Enhanced ApiException and subclasses
- openfga_sdk/api_client.py: Added operation_name parameter propagation
- openfga_sdk/sync/api_client.py: Added operation_name parameter propagation
Files added:
- test/error_handling_improvements_test.py: Unit tests
- test/integration_error_handling_test.py: Integration tests
- docker-compose.integration-test.yml: Test infrastructure
- run_integration_tests.sh: Helper script
- test/README_INTEGRATION_TESTS.md: Test documentation
Previously, operation_name parameter was added but never populated. This commit fixes that by extracting the operation name from telemetry attributes that are already passed to every API call. Changes: - api_client.py: Extract operation_name from telemetry if not provided - sync/api_client.py: Same for synchronous client - Integration tests: Verify operation names are set correctly - New tests: Verify telemetry extraction logic How it works: 1. Generated open_fga_api.py already sets telemetry attributes with method name 2. api_client.__call_api() extracts fga_client_request_method from telemetry 3. Operation name is automatically set on all exceptions 4. No changes needed to generated code Examples: - check() call -> exception.operation_name = "check" - write() call -> exception.operation_name = "write" - batch_check() call -> exception.operation_name = "batch_check" This matches the Java SDK implementation pattern where operation names are automatically tracked without modifying generated API code. Tests: 21 unit tests passing
…perties
Based on user feedback, direct access to parsed_exception has been hidden
to provide a cleaner, more intentional API design.
Changes:
- exceptions.py: parsed_exception getter now raises AttributeError with helpful message
- exceptions.py: parsed_exception setter kept for internal use by api_client
- Convenience properties (code, error_message, etc.) remain fully functional
- Tests updated to use convenience properties instead of parsed_exception
- Documentation updated to remove parsed_exception examples
Design rationale:
- Encourages using cleaner convenience properties (e.code, e.error_message)
- Prevents users from accessing internal parsed response object
- Setter still works for api_client.py to populate error details internally
- More intentional API surface with better user experience
User Impact:
- Code using e.parsed_exception.code will need to change to e.code
- Code using e.header.get('fga-request-id') continues to work
- All convenience properties work as before
Tests: 17 unit tests passing
Reverted breaking change - parsed_exception is now accessible again.
This makes the changes purely additive with zero breaking changes.
What works (backward compatible):
- e.parsed_exception.code - Still works!
- e.parsed_exception.message - Still works!
- e.header.get('fga-request-id') - Still works!
What's new (additive):
- e.code - Convenience property
- e.error_message - Convenience property
- e.request_id - Convenience property
- e.store_id - Convenience property
- e.authorization_model_id - Convenience property
- e.operation_name - Auto-extracted from telemetry
- e.is_validation_error() - Helper method
- e.is_retryable() - Helper method
- etc.
Tests: 21 unit tests passing
- Removed inner function imports of TelemetryAttributes - Top-level import already exists, use it directly - Fixes ruff F401 linting errors Linting: All ruff checks pass Tests: 21 unit tests passing
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.
No description provided.