Skip to content
Snippets Groups Projects
Verified Commit 4e4072a8 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

refactor error functions

parent 1aa9a7c5
No related branches found
No related tags found
No related merge requests found
......@@ -37,16 +37,6 @@ func (s *setting[C]) SetMnemonic(mnemonic string) *setting[C] {
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
func (s *setting[C]) Config() C {
return s.config
......
......@@ -5,6 +5,23 @@ import (
"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 MnemonicEmptyError = errors.New("mnemonic is empty")
var NoFileImportedError = errors.New("no file imported")
......@@ -49,13 +66,6 @@ func newUnsupportedTypeError(t reflect.Type) UnsupportedTypeError {
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
type UnsupportedReflectKindError error
......
......@@ -19,6 +19,8 @@ func TestResetErrors(t *testing.T) {
assert.True(t, c.HasErrors())
c.ResetErrors()
assert.False(t, c.HasErrors())
assert.Empty(t, c.Errors())
}
func TestNewFlagDoesNotExistError(t *testing.T) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment