Skip to content

Commit

Permalink
Merge pull request #214 from xmidt-org/denopink/patch/improve-ParseLo…
Browse files Browse the repository at this point in the history
…cator-errors

patch: improve `id.go`'s `ParseLocator` descriptions
  • Loading branch information
denopink authored Oct 30, 2024
2 parents cc4e56f + 535649e commit 2e0915b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions id.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ type Locator struct {
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 @@ func ParseLocator(locator string) (Locator, error) {
switch l.Scheme {
case SchemeDNS:
if l.Authority == "" {
return Locator{}, ErrorInvalidLocator
return Locator{}, fmt.Errorf("%w: empty authority", ErrorInvalidLocator)
}
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 @@ func ParseLocator(locator string) (Locator, error) {
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

0 comments on commit 2e0915b

Please sign in to comment.