mirror of https://github.com/hashicorp/terraform
parent
5ef20cf3a2
commit
91317a8608
@ -0,0 +1,21 @@
|
||||
package rpc
|
||||
|
||||
// This is a type that wraps error types so that they can be messaged
|
||||
// across RPC channels. Since "error" is an interface, we can't always
|
||||
// gob-encode the underlying structure. This is a valid error interface
|
||||
// implementer that we will push across.
|
||||
type BasicError struct {
|
||||
Message string
|
||||
}
|
||||
|
||||
func NewBasicError(err error) *BasicError {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &BasicError{err.Error()}
|
||||
}
|
||||
|
||||
func (e *BasicError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBasicError_ImplementsError(t *testing.T) {
|
||||
var _ error = new(BasicError)
|
||||
}
|
||||
|
||||
func TestBasicError_MatchesMessage(t *testing.T) {
|
||||
err := errors.New("foo")
|
||||
wrapped := NewBasicError(err)
|
||||
|
||||
if wrapped.Error() != err.Error() {
|
||||
t.Fatalf("bad: %#v", wrapped.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewBasicError_nil(t *testing.T) {
|
||||
r := NewBasicError(nil)
|
||||
if r != nil {
|
||||
t.Fatalf("bad: %#v", r)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue