Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create new test and refactor for errors/option #950

Merged
merged 7 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions internal/errors/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
//
package errors

// ErrInvalidOption represent the invalid option error.
// ErrInvalidOption represents the invalid option error.
type ErrInvalidOption struct {
err error
origin error
}

// NewErrInvalidOption represents a function to generate a new error of ErrInvalidOption that invalid option.
func NewErrInvalidOption(name string, val interface{}, errs ...error) error {
if len(errs) == 0 {
return &ErrInvalidOption{
Expand All @@ -46,24 +47,26 @@ func NewErrInvalidOption(name string, val interface{}, errs ...error) error {
}
}

// Error returns a string of ErrInvalidOption.err.
func (e *ErrInvalidOption) Error() string {
if e.err == nil {
return ""
}
return e.err.Error()
}

// Unwrap returns an origin error of ErrInvalidOption.
func (e *ErrInvalidOption) Unwrap() error {
return e.origin
}

/*
ErrCriticalOption
*/

// ErrCriticalOption represent the critical option error.
// ErrCriticalOption represents the critical option error.
type ErrCriticalOption struct {
err error
origin error
}

// NewErrCriticalOption represents a function to generate a new error of ErrCriticalOption that invalid option.
func NewErrCriticalOption(name string, val interface{}, errs ...error) error {
if len(errs) == 0 {
return &ErrCriticalOption{
Expand All @@ -90,10 +93,15 @@ func NewErrCriticalOption(name string, val interface{}, errs ...error) error {
}
}

// Error returns a string of ErrCriticalOption.err.
func (e *ErrCriticalOption) Error() string {
if e.err == nil {
return ""
}
return e.err.Error()
}

// Unwrap returns an origin error of ErrCriticalOption.
func (e *ErrCriticalOption) Unwrap() error {
return e.origin
}
Loading