Commit 302aaaea authored by Kirill Smelkov's avatar Kirill Smelkov

raiseif: Fix it wrt erraddcallingcontext()

erraddcallingcontext() already tries not to go beyond raise, but since
raiseif wes calling raise, it was omitting raiseif but not raise itself.
So an error could be like this

    cmd_restore: raiseif: mkdir ../R/1: file exists

while it should be

    cmd_restore: mkdir ../R/1: file exists

Fix it.
parent 7fcb8c67
...@@ -72,7 +72,7 @@ func raisef(format string, a ...interface{}) { ...@@ -72,7 +72,7 @@ func raisef(format string, a ...interface{}) {
func raiseif(err error) { func raiseif(err error) {
//if err != nil && !reflect.ValueOf(err).IsNil() { //if err != nil && !reflect.ValueOf(err).IsNil() {
if err != nil { if err != nil {
raise(err) panic(aserror(err))
} }
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
package main package main
import ( import (
"errors"
"strings" "strings"
"testing" "testing"
) )
...@@ -107,15 +108,34 @@ func do_raise11() { ...@@ -107,15 +108,34 @@ func do_raise11() {
do_raise1() do_raise1()
} }
func do_raise3if() {
raiseif(errors.New("3"))
}
func do_raise3if1() {
do_raise3if()
}
func TestErrAddCallingContext(t *testing.T) { func TestErrAddCallingContext(t *testing.T) {
myfunc := myfuncname() var tests = []struct{ f func(); wanterrcontext string } {
defer errcatch(func(e *Error) { {do_raise11, "do_raise11: do_raise1: 1"},
e = erraddcallingcontext(myfunc, e) {do_raise3if1, "do_raise3if1: do_raise3if: 3"},
msg, want := e.Error(), "do_raise11: do_raise1: 1" }
if msg != want {
t.Fatalf("err + calling context: %q ; want %q", msg, want) for _, tt := range tests {
} func() {
}) myfunc := myfuncname()
do_raise11() defer errcatch(func(e *Error) {
t.Fatal("error not caught") e = erraddcallingcontext(myfunc, e)
msg := e.Error()
if msg != tt.wanterrcontext {
t.Fatalf("err + calling context: %q ; want %q", msg, tt.wanterrcontext)
}
})
tt.f()
t.Fatal("error not caught")
}()
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment