Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Configuration
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Libraries
Go
Application
Configuration
Commits
4e4072a8
Verified
Commit
4e4072a8
authored
2 years ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
refactor error functions
Signed-off-by:
Volker Schukai
<
volker.schukai@schukai.com
>
parent
1aa9a7c5
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api.go
+0
-10
0 additions, 10 deletions
api.go
error.go
+17
-7
17 additions, 7 deletions
error.go
error_test.go
+2
-0
2 additions, 0 deletions
error_test.go
with
19 additions
and
17 deletions
api.go
+
0
−
10
View file @
4e4072a8
...
@@ -37,16 +37,6 @@ func (s *setting[C]) SetMnemonic(mnemonic string) *setting[C] {
...
@@ -37,16 +37,6 @@ func (s *setting[C]) SetMnemonic(mnemonic string) *setting[C] {
return
s
return
s
}
}
// Check if the setting contains errors
func
(
s
*
setting
[
C
])
HasErrors
()
bool
{
return
len
(
s
.
errors
)
>
0
}
// Get all errors
func
(
s
*
setting
[
C
])
Errors
()
[]
error
{
return
s
.
errors
}
// Config() returns the configuration
// Config() returns the configuration
func
(
s
*
setting
[
C
])
Config
()
C
{
func
(
s
*
setting
[
C
])
Config
()
C
{
return
s
.
config
return
s
.
config
...
...
This diff is collapsed.
Click to expand it.
error.go
+
17
−
7
View file @
4e4072a8
...
@@ -5,6 +5,23 @@ import (
...
@@ -5,6 +5,23 @@ import (
"reflect"
"reflect"
)
)
// ResetError is used to reset the error to nil
// After calling this function, the call HasErrors() will return false
func
(
s
*
setting
[
C
])
ResetErrors
()
*
setting
[
C
]
{
s
.
errors
=
[]
error
{}
return
s
}
// Check if the setting contains errors
func
(
s
*
setting
[
C
])
HasErrors
()
bool
{
return
len
(
s
.
errors
)
>
0
}
// Get all errors
func
(
s
*
setting
[
C
])
Errors
()
[]
error
{
return
s
.
errors
}
var
FileNameEmptyError
=
errors
.
New
(
"file name is empty"
)
var
FileNameEmptyError
=
errors
.
New
(
"file name is empty"
)
var
MnemonicEmptyError
=
errors
.
New
(
"mnemonic is empty"
)
var
MnemonicEmptyError
=
errors
.
New
(
"mnemonic is empty"
)
var
NoFileImportedError
=
errors
.
New
(
"no file imported"
)
var
NoFileImportedError
=
errors
.
New
(
"no file imported"
)
...
@@ -49,13 +66,6 @@ func newUnsupportedTypeError(t reflect.Type) UnsupportedTypeError {
...
@@ -49,13 +66,6 @@ func newUnsupportedTypeError(t reflect.Type) UnsupportedTypeError {
return
UnsupportedTypeError
(
errors
.
New
(
"type "
+
t
.
String
()
+
" is not supported"
))
return
UnsupportedTypeError
(
errors
.
New
(
"type "
+
t
.
String
()
+
" is not supported"
))
}
}
// ResetError is used to reset the error to nil
// After calling this function, the call HasErrors() will return false
func
(
s
*
setting
[
C
])
ResetErrors
()
*
setting
[
C
]
{
s
.
errors
=
[]
error
{}
return
s
}
// At the reflect level, some types are not supported
// At the reflect level, some types are not supported
type
UnsupportedReflectKindError
error
type
UnsupportedReflectKindError
error
...
...
This diff is collapsed.
Click to expand it.
error_test.go
+
2
−
0
View file @
4e4072a8
...
@@ -19,6 +19,8 @@ func TestResetErrors(t *testing.T) {
...
@@ -19,6 +19,8 @@ func TestResetErrors(t *testing.T) {
assert
.
True
(
t
,
c
.
HasErrors
())
assert
.
True
(
t
,
c
.
HasErrors
())
c
.
ResetErrors
()
c
.
ResetErrors
()
assert
.
False
(
t
,
c
.
HasErrors
())
assert
.
False
(
t
,
c
.
HasErrors
())
assert
.
Empty
(
t
,
c
.
Errors
())
}
}
func
TestNewFlagDoesNotExistError
(
t
*
testing
.
T
)
{
func
TestNewFlagDoesNotExistError
(
t
*
testing
.
T
)
{
...
...
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