mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
* chore: apply go fix modernizers from Go 1.26
automated refactoring: interface{} to any, slices.Contains,
and other idiomatic updates.
* feat(ci): add `go fix` check to Go analysis workflow
ensures Go 1.26 modernizers are applied, fails CI if `go fix ./...`
produces any changes (similar to existing `go fmt` enforcement)
31 lines
720 B
Go
31 lines
720 B
Go
package e
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime/debug"
|
|
)
|
|
|
|
// TypeErr returns an error with a string that explains what error was expected and what was received.
|
|
func TypeErr(expected, actual any) error {
|
|
return fmt.Errorf("expected type %T, got %T", expected, actual)
|
|
}
|
|
|
|
// compile time type check that HandlerError is an error
|
|
var _ error = New(nil)
|
|
|
|
// HandlerError adds a stack trace to an error
|
|
type HandlerError struct {
|
|
Err error
|
|
Stack []byte
|
|
}
|
|
|
|
// Error makes HandlerError implement error
|
|
func (err HandlerError) Error() string {
|
|
return fmt.Sprintf("%s in:\n%s", err.Err.Error(), err.Stack)
|
|
}
|
|
|
|
// New returns a new HandlerError
|
|
func New(err error) HandlerError {
|
|
return HandlerError{Err: err, Stack: debug.Stack()}
|
|
}
|