kubo/core/commands/e/error.go
Jan Winkelmann f287524949 cmd: use go-ipfs-cmds
License: MIT
Signed-off-by: keks <keks@cryptoscope.co>
2017-11-17 15:22:41 +01:00

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