1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-08-06 19:44:01 +08:00
Files
kubo/core/commands/e/error.go
Lucas Garron dd4e25c11b Fix typo in an error.go comment: "is adds" -> "adds".
License: MIT
Signed-off-by: Lucas Garron <code@garron.net>
2018-01-17 15:25:54 -08:00

31 lines
728 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 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()}
}