Ship a single shared instance of TwirpError rather than per-service
Preflight Checklist
- [X] I have searched the issue tracker for an issue that matches the one I want to file, without success.
Problem Description
We have a lot of service definitions, and each one generates a separate TwirpError class. It would be nice to have a single instance.
Benefits:
- Allows generic middleware to throw TwirpErrors without relying on any individual service
- Less PHP code to load
Proposed Solution
We could make this change in a backwards-compatible way by including a new protoc option to disable generating TwirpError and instead import it from twirphp directly.
Alternatives Considered
No response
Additional Information
No response
@noahseger thanks for opening an issue.
Allows generic middleware to throw TwirpErrors without relying on any individual service
You can already use the Twirp\Error interface to handle errors.
We could make this change in a backwards-compatible way by including a new protoc option to disable generating
TwirpErrorand instead import it fromtwirphpdirectly.
Sounds good to me. Would you be willing to provide a PR?
@sagikazarmark thanks so much for validating — yes, of course we can contribute a PR :) It might be a few weeks but will be a big help if you can review.
No rush! Happy to review early drafts and provide feedback.