diff --git a/_examples/golang-basics/example.gen.go b/_examples/golang-basics/example.gen.go index f739865..7263136 100644 --- a/_examples/golang-basics/example.gen.go +++ b/_examples/golang-basics/example.gen.go @@ -715,13 +715,18 @@ func (e WebRPCError) Unwrap() error { return e.cause } -func ErrorWithCause(rpcErr WebRPCError, cause error) WebRPCError { - err := rpcErr +func (e WebRPCError) WithCause(cause error) error { + err := e err.cause = cause err.Cause = cause.Error() return err } +// Deprecated: Use .WithCause() method on WebRPCError. +func ErrorWithCause(rpcErr WebRPCError, cause error) WebRPCError { + return rpcErr.WithCause(cause) +} + // Webrpc errors var ( ErrWebrpcEndpoint = WebRPCError{Code: 0, Name: "WebrpcEndpoint", Message: "endpoint error", HTTPStatus: 400} diff --git a/_examples/golang-imports/api.gen.go b/_examples/golang-imports/api.gen.go index 74258d6..be4b50b 100644 --- a/_examples/golang-imports/api.gen.go +++ b/_examples/golang-imports/api.gen.go @@ -482,13 +482,18 @@ func (e WebRPCError) Unwrap() error { return e.cause } -func ErrorWithCause(rpcErr WebRPCError, cause error) WebRPCError { - err := rpcErr +func (e WebRPCError) WithCause(cause error) error { + err := e err.cause = cause err.Cause = cause.Error() return err } +// Deprecated: Use .WithCause() method on WebRPCError. +func ErrorWithCause(rpcErr WebRPCError, cause error) WebRPCError { + return rpcErr.WithCause(cause) +} + // Webrpc errors var ( ErrWebrpcEndpoint = WebRPCError{Code: 0, Name: "WebrpcEndpoint", Message: "endpoint error", HTTPStatus: 400} diff --git a/errors.go.tmpl b/errors.go.tmpl index 26a47f5..ea94bc5 100644 --- a/errors.go.tmpl +++ b/errors.go.tmpl @@ -45,8 +45,8 @@ func (e WebRPCError) Unwrap() error { return e.cause } -func ErrorWithCause(rpcErr WebRPCError, cause error) WebRPCError { - err := rpcErr +func (e WebRPCError) WithCause(cause error) error { + err := e err.cause = cause err.Cause = cause.Error() {{- if $opts.errorStackTrace }} @@ -55,6 +55,11 @@ func ErrorWithCause(rpcErr WebRPCError, cause error) WebRPCError { return err } +// Deprecated: Use .WithCause() method on WebRPCError. +func ErrorWithCause(rpcErr WebRPCError, cause error) WebRPCError { + return rpcErr.WithCause(cause) +} + {{- if $opts.errorStackTrace -}} func (e WebRPCError) StackFrames() []uintptr { return e.frame.frames[:]