mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-10 10:47:51 +08:00
align kubo with unified golang ci linter from IPDX and rules used in boxo and other go packages addressed lint rules: - ST1000: added package comments - ST1020, ST1021, ST1022: fixed function/method comments - QF1001: applied De Morgan's law - QF1003: converted if-else chains to tagged switches - QF1004: replaced strings.Replace with strings.ReplaceAll - QF1008: simplified embedded struct field selectors - unconvert: removed unnecessary type conversions - usestdlibvars: used stdlib constants instead of literals disabled errcheck linter in .golangci.yml
32 lines
785 B
Go
32 lines
785 B
Go
// Package e provides error utilities for IPFS commands.
|
|
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 interface{}) 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()}
|
|
}
|