| 1 | package uuid |
| 2 | |
| 3 | import "fmt" |
| 4 | |
| 5 | // Error is a custom error type for UUID-related errors |
| 6 | type Error string |
| 7 | |
| 8 | // The strings defined in the errors is matching the previous behavior before |
| 9 | // the custom error type was implemented. The reason is that some people might |
| 10 | // be relying on the exact string representation to handle errors in their code. |
| 11 | const ( |
| 12 | // ErrInvalidFormat is returned when the UUID string representation does not |
| 13 | // match the expected format. See also ErrIncorrectFormatInString. |
| 14 | ErrInvalidFormat = Error("uuid: invalid UUID format") |
| 15 | |
| 16 | // ErrIncorrectFormatInString can be returned instead of ErrInvalidFormat. |
| 17 | // A separate error type is used because of how errors used to be formatted |
| 18 | // before custom error types were introduced. |
| 19 | ErrIncorrectFormatInString = Error("uuid: incorrect UUID format in string") |
| 20 | |
| 21 | // ErrIncorrectLength is returned when the UUID does not have the |
| 22 | // appropriate string length for parsing the UUID. |
| 23 | ErrIncorrectLength = Error("uuid: incorrect UUID length") |
| 24 | |
| 25 | // ErrIncorrectByteLength indicates the UUID byte slice length is invalid. |
| 26 | ErrIncorrectByteLength = Error("uuid: UUID must be exactly 16 bytes long") |
| 27 | |
| 28 | // ErrNoHwAddressFound is returned when a hardware (MAC) address cannot be |
| 29 | // found for UUID generation. |
| 30 | ErrNoHwAddressFound = Error("uuid: no HW address found") |
| 31 | |
| 32 | // ErrTypeConvertError is returned for type conversion operation fails. |
| 33 | ErrTypeConvertError = Error("uuid: cannot convert") |
| 34 | |
| 35 | // ErrInvalidVersion indicates an unsupported or invalid UUID version. |
| 36 | ErrInvalidVersion = Error("uuid:") |
| 37 | |
| 38 | // ErrV8FieldLength indicates a V8 custom field has incorrect length. |
| 39 | ErrV8FieldLength = Error("uuid: V8 field has incorrect length") |
| 40 | ) |
| 41 | |
| 42 | // Wrapped errors for backward compatibility. These wrap ErrIncorrectFormatInString |
| 43 | // so code like errors.Is(err, uuid.ErrIncorrectFormatInString) continues to work. |
| 44 | var ( |
| 45 | // ErrInvalidBraces is returned when braced format has invalid braces. |
| 46 | ErrInvalidBraces = fmt.Errorf("%w: invalid braces", ErrIncorrectFormatInString) |
| 47 | |
| 48 | // ErrInvalidURNPrefix is returned when URN format has invalid prefix. |
| 49 | ErrInvalidURNPrefix = fmt.Errorf("%w: invalid URN prefix", ErrIncorrectFormatInString) |
| 50 | |
| 51 | // ErrInvalidDashes is returned when canonical format has dashes not in expected positions. |
| 52 | ErrInvalidDashes = fmt.Errorf("%w: dashes were not in expected positions", ErrIncorrectFormatInString) |
| 53 | ) |
| 54 | |
| 55 | // Error returns the string representation of the UUID error. |
| 56 | func (e Error) Error() string { |
| 57 | return string(e) |
| 58 | } |