twitchtv / twirp

A simple RPC framework with protobuf service definitions
https://twitchtv.github.io/twirp/docs/intro.html
Apache License 2.0
7.19k stars 326 forks source link

Add Errorf function #311

Closed bouk closed 3 years ago

bouk commented 3 years ago

Hi there, it would be handy to have an Errorf function to make it easy to parameterize errors, alternatively we could have NewError and InternalError take args ...interface{} and then pass that to Sprintf in the function.

If you're open to this I can make a PR.

marioizquierdo commented 3 years ago

Thanks for the suggestion. That helper would be handy.

However, the errors package tries to be minimal by design. This ensures simplicity and performance.

Projects are encouraged to build their own error utils with their own constructors and wrappers. For example:

package errorutil

func TwirpErrorf(code twirp.ErrorCode, format string, a ...interface{}) {
    return twirp.NewError(code, fmt.Sprintf(format, a...))
}