-
Notifications
You must be signed in to change notification settings - Fork 35
Design: Enhanced Error Handling for Generated Clients (#100) #124
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
base: main
Are you sure you want to change the base?
Design: Enhanced Error Handling for Generated Clients (#100) #124
Conversation
This design document provides a comprehensive specification for enhancing the generated client's error handling capabilities including: - Rich exception hierarchy (APIError, ClientError, ServerError) - Parsed error models from OpenAPI specifications - Dual API pattern (simple + detailed response wrappers) - Full HTTP context (method, URL, headers, request IDs) - Support for multiple success codes and wildcard patterns - Type-safe error handling without Union type overhead - Backwards compatibility with existing HTTPException The design includes: - Complete architecture and component specifications - Usage examples for all API patterns - 10-phase implementation plan - Design rationale and backwards compatibility analysis Addresses Issue MarcoMuellner#100
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a comprehensive design document for implementing enhanced error handling in generated OpenAPI Python clients. The design addresses the need for rich, structured error handling with full HTTP context while maintaining backward compatibility and type safety.
Key Changes:
- Defines a three-tier exception hierarchy (APIError → ClientError/ServerError) with full HTTP context
- Introduces dual API pattern: simple (direct model returns) and detailed (response wrappers with metadata)
- Specifies automatic parsing of error response models from OpenAPI specifications
- Outlines 10-phase implementation plan spanning core exceptions, response wrappers, utilities, and code generation
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Changes: 1. Replace bare except with specific exception types (AttributeError, UnicodeDecodeError) 2. Narrow exception handling for error model parsing to specific types (ValidationError, ValueError, TypeError, JSONDecodeError) 3. Improve status code classification logic with better comments and defensive fallback to APIError for unexpected status codes 4. Add documentation for has_wildcard_success flag to clarify when it should be set (when OpenAPI spec uses '2XX' wildcard pattern) 5. Add inline comments explaining wildcard success handling in templates Addresses Copilot review comments on PR MarcoMuellner#124
dougborg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Addressed all Copilot review comments:
-
Bare except clause (line ~831): Changed from to to avoid catching system-level exceptions
-
Broad exception handling (line ~857): Narrowed from to for error model parsing
-
Misleading comment (line ~872): Improved status code classification logic with clearer comments explaining defensive handling and added fallback to APIError for unexpected status codes
-
Missing documentation (line ~1027): Added field to OpReturnType with clear documentation explaining it's set when OpenAPI spec uses '2XX' wildcard pattern, plus added inline comments in template code
All changes pushed in commit 4238443.
Summary
This PR adds a comprehensive design document for Issue #100: Enhanced error handling for generated OpenAPI clients.
What's Included
The design document (
DESIGN_ISSUE_100.md) specifies:Core Features
APIError→ClientError/ServerErrorwith full HTTP contextHTTPExceptionalias maintains existing code compatibilityArchitecture
DetailedResponse[T]wrapper with fluent API (on().otherwise().resolve())unwrap(),expect(),match(), type guards)Implementation Plan
10-phase rollout covering:
Next Steps
Related
Request for Feedback
Please review: