Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sidecar
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
sidecar
Commits
5a1a06b7
Commit
5a1a06b7
authored
Oct 22, 2021
by
suyanlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
😋
error select and combine
parent
d1c21a7b
Pipeline
#8152
canceled with stages
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
0 deletions
+48
-0
.gitignore
.gitignore
+1
-0
error.go
tool/error.go
+14
-0
error_test.go
tool/error_test.go
+33
-0
No files found.
.gitignore
View file @
5a1a06b7
...
...
@@ -15,3 +15,4 @@ goent.sum
testdata/
!internal/checker/testdata
pkg/filter/build/
tool/error.go
View file @
5a1a06b7
...
...
@@ -4,6 +4,7 @@ import (
"fmt"
"runtime"
"github.com/hashicorp/go-multierror"
"github.com/juju/errors"
)
...
...
@@ -19,3 +20,16 @@ func TraceError(err error, skip int) error {
}
return
fmt
.
Errorf
(
"%s:%d: %s"
,
file
,
line
,
err
)
}
func
CombineError
(
errs
...
error
)
error
{
return
multierror
.
Append
(
&
multierror
.
Error
{},
errs
...
)
.
ErrorOrNil
()
}
func
SelectError
(
errs
...
error
)
error
{
for
_
,
err
:=
range
errs
{
if
err
!=
nil
{
return
err
}
}
return
nil
}
tool/error_test.go
0 → 100644
View file @
5a1a06b7
package
tool
import
(
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func
TestCombineError
(
t
*
testing
.
T
)
{
err
:=
CombineError
(
nil
,
nil
)
assert
.
Nil
(
t
,
err
)
err
=
CombineError
(
fmt
.
Errorf
(
"err info"
),
nil
)
assert
.
NotNil
(
t
,
err
)
err
=
CombineError
(
nil
,
fmt
.
Errorf
(
"err info"
),
nil
)
assert
.
NotNil
(
t
,
err
)
t
.
Log
(
err
)
}
func
TestSelectError
(
t
*
testing
.
T
)
{
err1
:=
fmt
.
Errorf
(
"err info1"
)
err2
:=
fmt
.
Errorf
(
"err info2"
)
err
:=
SelectError
(
nil
,
nil
)
assert
.
Nil
(
t
,
err
)
err
=
SelectError
(
err1
,
nil
,
err2
)
assert
.
Equal
(
t
,
err
,
err1
)
err
=
SelectError
(
nil
,
err2
,
nil
,
err1
)
assert
.
Equal
(
t
,
err
,
err2
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment