Skip to content

Commit 66c95b9

Browse files
authored
Error shorthand WithCausef (e.WithCause + fmt.Errof) (#65)
* 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
1 parent fc75708 commit 66c95b9

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

_examples/golang-basics/example.gen.go

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_examples/golang-imports/api.gen.go

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

errors.go.tmpl

+11
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ func (e WebRPCError) WithCause(cause error) WebRPCError {
5858
return err
5959
}
6060

61+
func (e WebRPCError) WithCausef(fmt string, args ...interface{}) WebRPCError {
62+
cause := fmt.Errorf(fmt, args...)
63+
err := e
64+
err.cause = cause
65+
err.Cause = cause.Error()
66+
{{- if $opts.errorStackTrace }}
67+
runtime.Callers(1, err.frame.frames[:])
68+
{{- end}}
69+
return err
70+
}
71+
6172
// Deprecated: Use .WithCause() method on WebRPCError.
6273
func ErrorWithCause(rpcErr WebRPCError, cause error) WebRPCError {
6374
return rpcErr.WithCause(cause)

0 commit comments

Comments
 (0)