diff options
| author | 2026-06-06 21:51:58 +0000 | |
|---|---|---|
| committer | 2026-06-06 21:51:58 +0000 | |
| commit | 41e45d38f2d1ec78881f7e0ce778b2f43fed80a2 (patch) | |
| tree | 85378d19030bbc44e6fd22078a8fe7ac01c055f1 /ref/name/component.go | |
| parent | ref: detached -> direct (diff) | |
ref/name, object: Simplify errors
Diffstat (limited to 'ref/name/component.go')
| -rw-r--r-- | ref/name/component.go | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/ref/name/component.go b/ref/name/component.go index 40a736e2..b7d3bbb7 100644 --- a/ref/name/component.go +++ b/ref/name/component.go @@ -1,6 +1,9 @@ package name -import "strings" +import ( + "fmt" + "strings" +) const lockSuffix = ".lock" @@ -23,7 +26,7 @@ func nameDisposition(ch byte) byte { } } -func checkRefnameComponent(name string, flags *int, sanitized *strings.Builder, fullName string) (int, error) { +func checkRefnameComponent(name string, flags *int, sanitized *strings.Builder) (int, error) { var last byte var componentStart int @@ -47,7 +50,7 @@ func checkRefnameComponent(name string, flags *int, sanitized *strings.Builder, if sanitized != nil { truncateBuilder(sanitized, sanitized.Len()-1) } else { - return 0, &NameError{Name: fullName, Reason: "name contains '..'"} + return 0, fmt.Errorf("%w: name contains '..'", ErrInvalidName) } } case 3: @@ -55,21 +58,21 @@ func checkRefnameComponent(name string, flags *int, sanitized *strings.Builder, if sanitized != nil { overwriteBuilderAt(sanitized, sanitized.Len()-1) } else { - return 0, &NameError{Name: fullName, Reason: "name contains '@{'"} + return 0, fmt.Errorf("%w: name contains '@{'", ErrInvalidName) } } case 4: if sanitized != nil { overwriteBuilderAt(sanitized, sanitized.Len()-1) } else { - return 0, &NameError{Name: fullName, Reason: "name contains a forbidden character"} + return 0, fmt.Errorf("%w: name contains a forbidden character", ErrInvalidName) } case 5: if *flags&nameRefspecPattern == 0 { if sanitized != nil { overwriteBuilderAt(sanitized, sanitized.Len()-1) } else { - return 0, &NameError{Name: fullName, Reason: "name contains '*'"} + return 0, fmt.Errorf("%w: name contains '*'", ErrInvalidName) } } @@ -94,13 +97,13 @@ out: if sanitized != nil { overwriteBuilderAt(sanitized, componentStart) } else { - return 0, &NameError{Name: fullName, Reason: "component starts with '.'"} + return 0, fmt.Errorf("%w: component starts with '.'", ErrInvalidName) } } if componentLen >= len(lockSuffix) && name[componentLen-len(lockSuffix):componentLen] == lockSuffix { if sanitized == nil { - return 0, &NameError{Name: fullName, Reason: "component ends with .lock"} + return 0, fmt.Errorf("%w: component ends with .lock", ErrInvalidName) } for strings.HasSuffix(sanitized.String(), lockSuffix) { |
