aboutsummaryrefslogtreecommitdiff
path: root/config/errors.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-06-06 21:55:37 +0000
committerGravatar Runxi Yu2026-06-06 21:55:37 +0000
commitb08e04bf3f901faf18b3b24672ad313d816b8fb0 (patch)
treeb44ee7f31a4767b994640252c43434b4c3e34a5c /config/errors.go
parentref/name, object: Simplify errors (diff)
signatureNo signature
config: Use sentinel errors
Diffstat (limited to 'config/errors.go')
-rw-r--r--config/errors.go69
1 files changed, 26 insertions, 43 deletions
diff --git a/config/errors.go b/config/errors.go
index b1049b34..a26bb3cb 100644
--- a/config/errors.go
+++ b/config/errors.go
@@ -1,56 +1,39 @@
package config
-import "fmt"
+import (
+ "errors"
+ "fmt"
+)
-// ParseError describes a syntactic error in Git config input.
-type ParseError struct {
- Line int
- Reason string
-}
+var (
+ // ErrMissing indicates that a looked-up key does not exist.
+ ErrMissing = errors.New("config: key not found")
-func (err *ParseError) Error() string {
- if err.Line > 0 {
- return fmt.Sprintf("config: parse line %d: %s", err.Line, err.Reason)
- }
+ // ErrValueless indicates that a key exists but carries no value.
+ ErrValueless = errors.New("config: key has no value")
- return "config: parse: " + err.Reason
-}
+ // ErrValueEmpty indicates an empty value where one was required.
+ ErrValueEmpty = errors.New("config: empty value")
-// LookupError describes an invalid lookup result conversion.
-type LookupError struct {
- Kind Kind
- Operation string
-}
+ // ErrValueRange indicates a value outside the representable range.
+ ErrValueRange = errors.New("config: value out of range")
-func (err *LookupError) Error() string {
- switch err.Kind {
- case KindMissing:
- return fmt.Sprintf("config: %s: missing config value", err.Operation)
- case KindValueless:
- return fmt.Sprintf("config: %s: valueless config key", err.Operation)
- case KindString:
- return fmt.Sprintf("config: %s: invalid string config value", err.Operation)
- default:
- return fmt.Sprintf("config: %s: unknown value kind %d", err.Operation, err.Kind)
- }
-}
+ // ErrValueSyntax indicates a malformed value.
+ ErrValueSyntax = errors.New("config: invalid value syntax")
+)
+
+// ParseError describes a syntactic error in Git config input.
+type ParseError struct {
+ // Line is the 1-based input line where the error was detected.
+ Line int
-// ValueError describes a typed value conversion failure.
-type ValueError struct {
- Operation string
- Value string
- Reason string
- Err error
+ reason string
}
-func (err *ValueError) Error() string {
- if err.Err != nil {
- return fmt.Sprintf("config: %s %q: %s: %v", err.Operation, err.Value, err.Reason, err.Err)
+func (err *ParseError) Error() string {
+ if err.Line > 0 {
+ return fmt.Sprintf("config: parse line %d: %s", err.Line, err.reason)
}
- return fmt.Sprintf("config: %s %q: %s", err.Operation, err.Value, err.Reason)
-}
-
-func (err *ValueError) Unwrap() error {
- return err.Err
+ return "config: parse: " + err.reason
}