forked from jetify-com/typeid-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
31 lines (25 loc) · 885 Bytes
/
errors.go
File metadata and controls
31 lines (25 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package typeid
import "fmt"
// ErrValidation is a sentinel error for validation failures.
// Use errors.Is(err, ErrValidation) to check if an error is a validation error.
var ErrValidation error = &validationError{}
// validationError represents errors that occur during TypeID validation
type validationError struct {
Message string
Cause error // Optional wrapped error (e.g., from base32)
}
// Error implements the error interface
func (e *validationError) Error() string {
if e.Cause != nil {
return fmt.Sprintf("typeid: %s: %v", e.Message, e.Cause)
}
return fmt.Sprintf("typeid: %s", e.Message)
}
// Unwrap returns the underlying cause if present
func (e *validationError) Unwrap() error {
return e.Cause
}
// Is implements error matching and returns true for any validationError
func (e *validationError) Is(target error) bool {
return target == ErrValidation
}