-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated error type based on feedback
- Loading branch information
Patrik Lindahl
committed
Apr 8, 2024
1 parent
a3a3081
commit 09b5842
Showing
6 changed files
with
194 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,22 @@ | ||
package uuid | ||
|
||
import ( | ||
"fmt" | ||
type Error string | ||
|
||
const ( | ||
ErrInvalidFormat = Error("uuid: invalid UUID format") | ||
ErrIncorrectFormatInString = Error("uuid: incorrect UUID format in string") | ||
ErrIncorrectLength = Error("uuid: incorrect UUID length") | ||
ErrIncorrectByteLength = Error("uuid: UUID must be exactly 16 bytes long") | ||
ErrNoHwAddressFound = Error("uuid: no HW address found") | ||
ErrTypeConvertError = Error("uuid: cannot convert") | ||
ErrInvalidVersion = Error("uuid:") | ||
) | ||
|
||
// ErrUUID is the base error type for errors generated by this package | ||
type ErrUUID struct{} | ||
|
||
func (e *ErrUUID) Error() string { | ||
return "uuid" | ||
} | ||
|
||
// ErrUUIDInvalidFormat is a specialized error that is returned when there is | ||
// a problem parsing UUID data | ||
type ErrUUIDInvalidFormat struct { | ||
err error | ||
} | ||
|
||
func (e *ErrUUIDInvalidFormat) Error() string { | ||
return e.err.Error() | ||
} | ||
|
||
func (e *ErrUUIDInvalidFormat) Unwrap() error { | ||
return e.err | ||
func (e Error) Error() string { | ||
return string(e) | ||
} | ||
|
||
func (e *ErrUUIDInvalidFormat) Is(target error) bool { | ||
_, ok := target.(*ErrUUIDInvalidFormat) | ||
func (e Error) Is(target error) bool { | ||
_, ok := target.(*Error) | ||
return ok | ||
} | ||
|
||
func invalidFormat() error { | ||
return &ErrUUIDInvalidFormat{ | ||
err: fmt.Errorf("%w: invalid UUID format", &ErrUUID{}), | ||
} | ||
} | ||
|
||
func invalidFormatf(format string, a ...any) error { | ||
formattedError := fmt.Errorf(format, a...) | ||
|
||
return &ErrUUIDInvalidFormat{ | ||
err: fmt.Errorf("%w: %v", &ErrUUID{}, formattedError), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.