Documentation ¶
Overview ¶
Package errhelp contains error helper functions.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FirstError ¶
FirstError gets the first error in errs that is non-nil, or nil if none exist.
Example ¶
ExampleFirstError is a testable example for FirstError.
package main import ( "errors" "fmt" "github.com/c4-project/c4t/internal/helper/errhelp" ) func main() { fmt.Println("FirstError() == nil:", errhelp.FirstError() == nil) fmt.Println("FirstError(x, y) ==", errhelp.FirstError(errors.New("x"), errors.New("y"))) }
Output: FirstError() == nil: true FirstError(x, y) == x
func TimeoutOrFirstError ¶
TimeoutOrFirstError returns ctx.Err() if it is a deadline-exceeded error, or the first error in errs that is non-nil, if any exist.
Example ¶
ExampleTimeoutFirstError is a testable example for FirstError.
package main import ( "context" "errors" "fmt" "github.com/c4-project/c4t/internal/helper/errhelp" ) func main() { ctx := context.Background() fmt.Println("TimeoutOrFirstError(ok ctx) ==", errhelp.TimeoutOrFirstError(ctx)) fmt.Println("TimeoutOrFirstError(ok ctx, x, y) ==", errhelp.TimeoutOrFirstError(ctx, errors.New("x"), errors.New("y"))) tctx, cf := context.WithTimeout(ctx, 0) defer cf() fmt.Println("TimeoutOrFirstError(t/o ctx) ==", errhelp.TimeoutOrFirstError(tctx)) fmt.Println("TimeoutOrFirstError(t/o ctx, x, y) ==", errhelp.TimeoutOrFirstError(tctx, errors.New("x"), errors.New("y"))) }
Output: TimeoutOrFirstError(ok ctx) == <nil> TimeoutOrFirstError(ok ctx, x, y) == x TimeoutOrFirstError(t/o ctx) == context deadline exceeded TimeoutOrFirstError(t/o ctx, x, y) == context deadline exceeded
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.