Commit f674c8f7 authored by Kirill Smelkov's avatar Kirill Smelkov

xerr/Errorv: Don't forget to handle empty-vector case in Error()

Previously Error() was giving "0 errors", but "" seems to be a better
choice.

Anyway proper usage of Errorv is to call .Err() when handing result to
some where so this way empty-vector case becomes nil.
parent 20c2add8
...@@ -21,7 +21,10 @@ import ( ...@@ -21,7 +21,10 @@ import (
type Errorv []error type Errorv []error
func (errv Errorv) Error() string { func (errv Errorv) Error() string {
if len(errv) == 1 { switch len(errv) {
case 0:
return ""
case 1:
return errv[0].Error() return errv[0].Error()
} }
......
...@@ -32,6 +32,8 @@ func TestErrorv(t *testing.T) { ...@@ -32,6 +32,8 @@ func TestErrorv(t *testing.T) {
} }
} }
check(nil, "")
err1 := errors.New("err1") err1 := errors.New("err1")
err2 := errors.New("err2") err2 := errors.New("err2")
......
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