Skip to content

Commit

Permalink
Added missing documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrik Lindahl committed Apr 9, 2024
1 parent fec3c0a commit 56acf31
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions error.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
package uuid

// Error is a custom error type for UUID-related errors
type Error string

// The strings defined in the errors is matching the previous behavior before
// the custom error type was implemented. The reason is that some people might
// be relying on the exact string representation to handle errors in their code.
const (
ErrInvalidFormat = Error("uuid: invalid UUID format")
// ErrInvalidFormat is returned when the UUID string representation does not
// match the expected format. See also ErrIncorrectFormatInString.
ErrInvalidFormat = Error("uuid: invalid UUID format")

// ErrIncorrectFormatInString can be returned instead of ErrInvalidFormat.
// A separate error type is used because of how errors used to be formatted
// before custom error types were introduced.
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:")

// ErrIncorrectLength is returned when the UUID does not have the
// appropriate string length for parsing the UUID.
ErrIncorrectLength = Error("uuid: incorrect UUID length")

// ErrIncorrectByteLength indicates the UUID byte slice length is invalid.
ErrIncorrectByteLength = Error("uuid: UUID must be exactly 16 bytes long")

// ErrNoHwAddressFound is returned when a hardware (MAC) address cannot be
// found for UUID generation.
ErrNoHwAddressFound = Error("uuid: no HW address found")

// ErrTypeConvertError is returned for type conversion operation fails.
ErrTypeConvertError = Error("uuid: cannot convert")

// ErrInvalidVersion indicates an unsupported or invalid UUID version.
ErrInvalidVersion = Error("uuid:")
)

// Error returns the string representation of the UUID error.
func (e Error) Error() string {
return string(e)
}

// Is checks if the target error is a UUID Error
func (e Error) Is(target error) bool {
_, ok := target.(*Error)
return ok
Expand Down

0 comments on commit 56acf31

Please sign in to comment.