Documentation ¶
Overview ¶
Package errorhelper contains error-related helpers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CallerError ¶ added in v0.6.0
CallerError prepends the provided error (if not nil) with caller function name. If 'err' is nil, nil is returned.
func Must2 ¶ added in v0.5.0
Must2 returns ('r1', 'r2') if 'err' is nil. Otherwise, it panics with 'err'.
func PanicToError ¶ added in v0.4.0
PanicToError converts panic to error in the following way:
- if surrounding function panics with an error, this error is returned;
- if surrounding function panics with a string, the error wrapping this string is returned;
- if surrounding function panics with a fmt.Stringer, the error wrapping fmt.Stringer.String is returned;
- if surrounding function panics with an encoding.TextMarshaler, the error wrapping encoding.TextMarshaler.MarshalText is returned;
- otherwise the panic is reraised.
PanicToError must be called from a defer statement:
func Example() (err error) { defer func() { PanicToError(recover(), &err) }() return nil }
(See tests.)
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.