Преглед изворни кода

Merge pull request #20 from fkautz/pr_out_wrapping_returns_nil_rather_than_error_nil_

Wrapping returns nil rather than Error(<nil>).
Conrad Irwin пре 7 година
родитељ
комит
d98b870cc4
2 измењених фајлова са 9 додато и 2 уклоњено
  1. 7 0
      error.go
  2. 2 2
      error_test.go

+ 7 - 0
error.go

@@ -91,6 +91,10 @@ func New(e interface{}) *Error {
 // fmt.Errorf("%v"). The skip parameter indicates how far up the stack
 // to start the stacktrace. 0 is from the current call, 1 from its caller, etc.
 func Wrap(e interface{}, skip int) *Error {
+	if e == nil {
+		return nil
+	}
+
 	var err error
 
 	switch e := e.(type) {
@@ -117,6 +121,9 @@ func Wrap(e interface{}, skip int) *Error {
 // up the stack to start the stacktrace. 0 is from the current call,
 // 1 from its caller, etc.
 func WrapPrefix(e interface{}, prefix string, skip int) *Error {
+	if e == nil {
+		return nil
+	}
 
 	err := Wrap(e, 1+skip)
 

+ 2 - 2
error_test.go

@@ -129,7 +129,7 @@ func TestWrapError(t *testing.T) {
 		t.Errorf("Constructor with an Error failed")
 	}
 
-	if Wrap(nil, 0).Error() != "<nil>" {
+	if Wrap(nil, 0) != nil {
 		t.Errorf("Constructor with nil failed")
 	}
 }
@@ -159,7 +159,7 @@ func TestWrapPrefixError(t *testing.T) {
 		t.Errorf("WrapPrefix changed the original error")
 	}
 
-	if WrapPrefix(nil, "prefix", 0).Error() != "prefix: <nil>" {
+	if WrapPrefix(nil, "prefix", 0) != nil {
 		t.Errorf("Constructor with nil failed")
 	}