Skip to content

Commit

Permalink
Error shorthand WithCausef (e.WithCause + fmt.Errof) (#65)
Browse files Browse the repository at this point in the history
* Update errors.go.tmpl

* Update errors.go.tmpl

* gen files

* generate with 15.2

* use webrpc built from scratch as CI

* use interface

* errorStackTrace support
  • Loading branch information
klaidliadon authored Apr 23, 2024
1 parent fc75708 commit 66c95b9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
10 changes: 9 additions & 1 deletion _examples/golang-basics/example.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion _examples/golang-imports/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions errors.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ func (e WebRPCError) WithCause(cause error) WebRPCError {
return err
}

func (e WebRPCError) WithCausef(fmt string, args ...interface{}) WebRPCError {
cause := fmt.Errorf(fmt, args...)
err := e
err.cause = cause
err.Cause = cause.Error()
{{- if $opts.errorStackTrace }}
runtime.Callers(1, err.frame.frames[:])
{{- end}}
return err
}

// Deprecated: Use .WithCause() method on WebRPCError.
func ErrorWithCause(rpcErr WebRPCError, cause error) WebRPCError {
return rpcErr.WithCause(cause)
Expand Down

0 comments on commit 66c95b9

Please sign in to comment.