Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
22d978fe
Commit
22d978fe
authored
3 years ago
by
Jan Semmelink
Browse files
Options
Downloads
Patches
Plain Diff
Added readme and test for nexted Is()
parent
34f2caf5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
errors/README.md
+6
-0
6 additions, 0 deletions
errors/README.md
errors/errors_test.go
+24
-0
24 additions, 0 deletions
errors/errors_test.go
with
30 additions
and
0 deletions
errors/README.md
+
6
−
0
View file @
22d978fe
...
...
@@ -175,3 +175,9 @@ This function can be used also for logging to determine the caller from the runt
## func Stack()
This function is similar to Caller() but reports an array of callers, not only one.
## func Is()
You can compare a message with errors.Is() to some error specification.
It will look at the error or any cause to match the spec.
The spec is the error message.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
errors/errors_test.go
+
24
−
0
View file @
22d978fe
...
...
@@ -109,6 +109,23 @@ func TestIs(t *testing.T) {
t
.
Logf
(
"n=%d worked"
,
n
)
}
}
//same but err is wrapped deeper
for
n
:=
0
;
n
<=
4
;
n
++
{
if
err
:=
UserExists
(
n
);
err
!=
nil
{
switch
{
case
errors
.
Is
(
err
,
errNotFound
)
:
t
.
Logf
(
"u=%d failed with NOT FOUND"
,
n
)
case
errors
.
Is
(
err
,
errDisabled
)
:
t
.
Logf
(
"u=%d failed because disabled"
,
n
)
default
:
t
.
Logf
(
"u=%d failed for unknown cause: %+v"
,
n
,
err
)
}
}
else
{
t
.
Logf
(
"u=%d worked"
,
n
)
}
}
}
var
(
...
...
@@ -130,3 +147,10 @@ func ReadDb(x int) error {
return
errors
.
Errorf
(
"invalid x=%d"
,
x
)
}
}
func
UserExists
(
u
int
)
error
{
if
err
:=
ReadDb
(
u
);
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"cannot read user %d"
,
u
)
}
return
nil
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment