fix wire error bugs

master
Jordan Orelli 4 years ago
parent 5608cf4583
commit 77682ac01e

@ -1,33 +1,25 @@
package wire package wire
import ( import (
"encoding/json" "errors"
"fmt" "fmt"
) )
type Error struct { type Error struct {
val error Message string `json:"message"`
parent error
} }
func (e Error) Error() string { return e.val.Error() } func (e Error) Error() string { return e.Message }
func (e Error) NetTag() string { return "error" } func (e Error) NetTag() string { return "error" }
func (e Error) Unwrap() error { return e.val } func (e Error) Unwrap() error { return e.parent }
func (e Error) MarshalJSON() ([]byte, error) {
return json.Marshal(e.Error())
}
func (e *Error) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
*e = Errorf(s)
return nil
}
func Errorf(t string, args ...interface{}) Error { func Errorf(t string, args ...interface{}) Error {
return Error{val: fmt.Errorf(t, args...)} err := fmt.Errorf(t, args...)
return Error{
Message: err.Error(),
parent: errors.Unwrap(err),
}
} }
func init() { func init() {

Loading…
Cancel
Save