twirp icon indicating copy to clipboard operation
twirp copied to clipboard

Ship a single shared instance of TwirpError rather than per-service

Open noahseger opened this issue 1 year ago • 3 comments

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 avatar Jul 31 '24 16:07 noahseger

@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 TwirpError and instead import it from twirphp directly.

Sounds good to me. Would you be willing to provide a PR?

sagikazarmark avatar Sep 20 '24 15:09 sagikazarmark

@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.

noahseger avatar Sep 23 '24 16:09 noahseger

No rush! Happy to review early drafts and provide feedback.

sagikazarmark avatar Sep 23 '24 21:09 sagikazarmark