Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor 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
elixxir
client
Commits
b9971bf5
Commit
b9971bf5
authored
3 years ago
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Unexport globals in bindings/errors.go
parent
b2c50b46
No related branches found
No related tags found
1 merge request
!23
Release
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bindings/errors.go
+12
-12
12 additions, 12 deletions
bindings/errors.go
bindings/errors_test.go
+2
-2
2 additions, 2 deletions
bindings/errors_test.go
with
14 additions
and
14 deletions
bindings/errors.go
+
12
−
12
View file @
b9971bf5
...
...
@@ -16,10 +16,10 @@ import (
"sync"
)
//
E
rrToUserErr maps backend patterns to user friendly error messages.
//
e
rrToUserErr maps backend patterns to user friendly error messages.
// Example format:
// (Back-end) "Building new HostPool because no HostList stored:": (Front-end) "Missing host list",
var
E
rrToUserErr
=
map
[
string
]
string
{
var
e
rrToUserErr
=
map
[
string
]
string
{
// Registration errors
//"cannot create username when network is not health" :
// "Cannot create username, unable to connect to network",
...
...
@@ -37,7 +37,7 @@ var ErrToUserErr = map[string]string{
// "Could not get network status",
}
var
E
rrorMux
sync
.
RWMutex
var
e
rrorMux
sync
.
RWMutex
// Error codes
const
UnrecognizedCode
=
"UR: "
...
...
@@ -47,14 +47,14 @@ const UnrecognizedMessage = UnrecognizedCode + "Unrecognized error from XX backe
// a backend generated error. These may be error specifically written by
// the backend team or lower level errors gotten from low level dependencies.
// This function will parse the error string for common errors provided from
//
E
rrToUserErr to provide a more user-friendly error message for the front end.
//
e
rrToUserErr to provide a more user-friendly error message for the front end.
// If the error is not common, some simple parsing is done on the error message
// to make it more user-accessible, removing backend specific jargon.
func
ErrorStringToUserFriendlyMessage
(
errStr
string
)
string
{
E
rrorMux
.
RLock
()
defer
E
rrorMux
.
RUnlock
()
e
rrorMux
.
RLock
()
defer
e
rrorMux
.
RUnlock
()
// Go through common errors
for
backendErr
,
userFriendly
:=
range
E
rrToUserErr
{
for
backendErr
,
userFriendly
:=
range
e
rrToUserErr
{
// Determine if error contains a common error
if
strings
.
Contains
(
errStr
,
backendErr
)
{
return
userFriendly
...
...
@@ -89,13 +89,13 @@ func ErrorStringToUserFriendlyMessage(errStr string) string {
}
// UpdateCommonErrors takes the passed in contents of a JSON file and updates the
//
E
rrToUserErr map with the contents of the json file. The JSON's expected format
// conform with the commented examples provides in
E
rrToUserErr above.
//
e
rrToUserErr map with the contents of the json file. The JSON's expected format
// conform with the commented examples provides in
e
rrToUserErr above.
// NOTE that you should not pass in a file path, but a preloaded JSON file
func
UpdateCommonErrors
(
jsonFile
string
)
error
{
E
rrorMux
.
Lock
()
defer
E
rrorMux
.
Unlock
()
err
:=
json
.
Unmarshal
([]
byte
(
jsonFile
),
&
E
rrToUserErr
)
e
rrorMux
.
Lock
()
defer
e
rrorMux
.
Unlock
()
err
:=
json
.
Unmarshal
([]
byte
(
jsonFile
),
&
e
rrToUserErr
)
if
err
!=
nil
{
return
errors
.
WithMessage
(
err
,
"Failed to unmarshal json file, "
+
"did you pass in the contents or the path?"
)
...
...
This diff is collapsed.
Click to expand it.
bindings/errors_test.go
+
2
−
2
View file @
b9971bf5
...
...
@@ -22,7 +22,7 @@ func TestErrorStringToUserFriendlyMessage(t *testing.T) {
"Failed to pull up friend requests"
}
for
i
,
exampleErr
:=
range
backendErrs
{
E
rrToUserErr
[
exampleErr
]
=
userErrs
[
i
]
e
rrToUserErr
[
exampleErr
]
=
userErrs
[
i
]
}
// Check if a mapped common error returns the expected user friendly error
...
...
@@ -93,7 +93,7 @@ func TestClient_UpdateCommonErrors(t *testing.T) {
t
.
Fatalf
(
"UpdateCommonErrors error: %v"
,
err
)
}
val
,
ok
:=
E
rrToUserErr
[
key
]
val
,
ok
:=
e
rrToUserErr
[
key
]
if
!
ok
{
t
.
Fatalf
(
"Expected entry was not populated"
)
}
...
...
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