treewide: rename to hakurei
All checks were successful
Test / Create distribution (push) Successful in 43s
Test / Sandbox (push) Successful in 2m18s
Test / Hakurei (push) Successful in 3m10s
Test / Sandbox (race detector) (push) Successful in 3m30s
Test / Hakurei (race detector) (push) Successful in 4m43s
Test / Fpkg (push) Successful in 5m4s
Test / Flake checks (push) Successful in 1m12s
All checks were successful
Test / Create distribution (push) Successful in 43s
Test / Sandbox (push) Successful in 2m18s
Test / Hakurei (push) Successful in 3m10s
Test / Sandbox (race detector) (push) Successful in 3m30s
Test / Hakurei (race detector) (push) Successful in 4m43s
Test / Fpkg (push) Successful in 5m4s
Test / Flake checks (push) Successful in 1m12s
Fortify makes little sense for a container tool. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -1,88 +0,0 @@
|
||||
package fmsg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// baseError implements a basic error container
|
||||
type baseError struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e *baseError) Error() string {
|
||||
return e.Err.Error()
|
||||
}
|
||||
|
||||
func (e *baseError) Unwrap() error {
|
||||
return e.Err
|
||||
}
|
||||
|
||||
// BaseError implements an error container with a user-facing message
|
||||
type BaseError struct {
|
||||
message string
|
||||
baseError
|
||||
}
|
||||
|
||||
// Message returns a user-facing error message
|
||||
func (e *BaseError) Message() string {
|
||||
return e.message
|
||||
}
|
||||
|
||||
// WrapError wraps an error with a corresponding message.
|
||||
func WrapError(err error, a ...any) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return wrapError(err, fmt.Sprintln(a...))
|
||||
}
|
||||
|
||||
// WrapErrorSuffix wraps an error with a corresponding message with err at the end of the message.
|
||||
func WrapErrorSuffix(err error, a ...any) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return wrapError(err, fmt.Sprintln(append(a, err)...))
|
||||
}
|
||||
|
||||
// WrapErrorFunc wraps an error with a corresponding message returned by f.
|
||||
func WrapErrorFunc(err error, f func(err error) string) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return wrapError(err, f(err))
|
||||
}
|
||||
|
||||
func wrapError(err error, message string) *BaseError {
|
||||
return &BaseError{message, baseError{err}}
|
||||
}
|
||||
|
||||
var (
|
||||
baseErrorType = reflect.TypeFor[*BaseError]()
|
||||
)
|
||||
|
||||
func AsBaseError(err error, target **BaseError) bool {
|
||||
v := reflect.ValueOf(err)
|
||||
if !v.CanConvert(baseErrorType) {
|
||||
return false
|
||||
}
|
||||
|
||||
*target = v.Convert(baseErrorType).Interface().(*BaseError)
|
||||
return true
|
||||
}
|
||||
|
||||
func PrintBaseError(err error, fallback string) {
|
||||
var e *BaseError
|
||||
|
||||
if AsBaseError(err, &e) {
|
||||
if msg := e.Message(); strings.TrimSpace(msg) != "" {
|
||||
log.Print(msg)
|
||||
return
|
||||
}
|
||||
Verbose("*"+fallback, err)
|
||||
return
|
||||
}
|
||||
log.Println(fallback, err)
|
||||
}
|
||||
Reference in New Issue
Block a user