Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch: improve id.go's ParseLocator descriptions #214

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions id.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
func ParseLocator(locator string) (Locator, error) {
match := LocatorPattern.FindStringSubmatch(locator)
if match == nil {
return Locator{}, ErrorInvalidLocator
return Locator{}, fmt.Errorf("%w: `%s` does not match expected locator pattern", ErrorInvalidLocator, locator)
}

var l Locator
Expand All @@ -154,11 +154,11 @@
switch l.Scheme {
case SchemeDNS:
if l.Authority == "" {
return Locator{}, ErrorInvalidLocator
return Locator{}, fmt.Errorf("%w: empty authority", ErrorInvalidLocator)

Check warning on line 157 in id.go

View check run for this annotation

Codecov / codecov/patch

id.go#L157

Added line #L157 was not covered by tests
}
case SchemeEvent:
if l.Authority == "" {
return Locator{}, ErrorInvalidLocator
return Locator{}, fmt.Errorf("%w: empty authority", ErrorInvalidLocator)
}
if l.Service != "" {
l.Ignored = "/" + l.Service + l.Ignored
Expand All @@ -167,7 +167,7 @@
case SchemeMAC, SchemeUUID, SchemeSerial, SchemeSelf:
id, err := makeDeviceID(l.Scheme, l.Authority)
if err != nil {
return Locator{}, err
return Locator{}, fmt.Errorf("%w: unable to make a device ID with scheme `%s` and authority `%s`", err, l.Scheme, l.Authority)
}
l.ID = id
default:
Expand Down
2 changes: 1 addition & 1 deletion wrpvalidator/metaValidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func ExampleMetaValidator() {
}
}

// Output: source errors: validator `source`: Validator error [Source] err=invalid Source name 'external.com': invalid locator
// Output: source errors: validator `source`: Validator error [Source] err=invalid Source name 'external.com': invalid locator: `external.com` does not match expected locator pattern
}

func TestMetaValidatorUnmarshal(t *testing.T) {
Expand Down