package y
import (
"errors"
"fmt"
"log"
)
var debugMode = false
func Check (err error ) {
if err != nil {
log .Fatalf ("%+v" , Wrap (err , "" ))
}
}
func Check2 (_ interface {}, err error ) {
Check (err )
}
func AssertTrue (b bool ) {
if !b {
log .Fatalf ("%+v" , errors .New ("Assert failed" ))
}
}
func AssertTruef (b bool , format string , args ...interface {}) {
if !b {
log .Fatalf ("%+v" , fmt .Errorf (format , args ...))
}
}
func Wrap (err error , msg string ) error {
if !debugMode {
if err == nil {
return nil
}
return fmt .Errorf ("%s err: %+v" , msg , err )
}
return fmt .Errorf ("%s: %w" , msg , err )
}
func Wrapf (err error , format string , args ...interface {}) error {
return Wrap (err , fmt .Sprintf (format , args ...))
}
func CombineErrors (one , other error ) error {
if one != nil && other != nil {
return fmt .Errorf ("%v; %v" , one , other )
}
if one != nil && other == nil {
return fmt .Errorf ("%v" , one )
}
if one == nil && other != nil {
return fmt .Errorf ("%v" , other )
}
return nil
}
The pages are generated with Golds v0.8.4 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .