github.com/alloyzeus/go-azfl@v0.0.0-20231220071816-9740126a2d07/errors/errors.go (about) 1 // Package errors provides extra functionalities to that of Go's stdlib 2 // errors package. 3 package errors 4 5 import ( 6 "errors" 7 ) 8 9 // Wraps Go's errors 10 var ( 11 As = errors.As 12 Is = errors.Is 13 New = errors.New // Prefer Msg instead as it has better semantic 14 Msg = errors.New 15 Unwrap = errors.Unwrap 16 ) 17 18 //TODO: fields. 19 // e.g., errors.Msg("error message", errors.Str("name", name), errors.Err(err)) 20 // or errors.With().Str("name", name).Err(err).Msg("error message") 21 // or errors.With().StrErr("name", nameErr).Msg("error message") 22 // (sounds like structured logging? exactly!) 23 24 const ( 25 // ErrUnimplemented is used to declare that a functionality, or part of it, 26 // has not been implemented. This could be well mapped to some protocols' 27 // status code, e.g., HTTP's 501 and gRPC's 12 . 28 ErrUnimplemented = constantErrorDescriptor("unimplemented") 29 ) 30 31 func errorString(err error) string { 32 if err != nil { 33 return err.Error() 34 } 35 return "" 36 }