Skip to content

Commit

Permalink
Merge pull request #2493 from hashicorp/f/resource-id-parsers-use-seg…
Browse files Browse the repository at this point in the history
…ment-not-found-error

tools/generator-go-sdk: updating the ID Parsers to use the new `SegmentNotFound` error type available in hashicorp/go-azure-helpers#155
  • Loading branch information
tombuildsstuff authored May 10, 2023
2 parents a51f316 + 4de63c2 commit 9a05e7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tools/generator-go-sdk/generator/templater_id_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (r resourceIdTemplater) parseFunction(nameWithoutSuffix string, caseSensiti
if v, ok := parsed.Parsed[%[1]q]; true {
if !ok {
return nil, fmt.Errorf("the segment '%[1]s' was not found in the resource id %%q", input)
return nil, resourceids.NewSegmentNotSpecifiedError(id, %[1]q, *parsed)
}
%[1]s, err := parse%[3]s(v)
Expand All @@ -295,7 +295,7 @@ func (r resourceIdTemplater) parseFunction(nameWithoutSuffix string, caseSensiti
{
lines = append(lines, fmt.Sprintf(`
if id.%[2]s, ok = parsed.Parsed[%[1]q]; !ok {
return nil, fmt.Errorf("the segment '%[1]s' was not found in the resource id %%q", input)
return nil, resourceids.NewSegmentNotSpecifiedError(id, %[1]q, *parsed)
}
`, segment.Name, strings.Title(segment.Name)))

Expand Down
8 changes: 4 additions & 4 deletions tools/generator-go-sdk/generator/templater_id_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var _ resourceids.ResourceId = BasicTestId{}
var ok bool
id := BasicTestId{}
if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok {
return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input)
return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed)
}
return &id, nil
Expand All @@ -92,7 +92,7 @@ var _ resourceids.ResourceId = BasicTestId{}
var ok bool
id := BasicTestId{}
if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok {
return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input)
return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed)
}
return &id, nil
Expand Down Expand Up @@ -222,7 +222,7 @@ func ParseConstantOnlyID(input string) (*ConstantOnlyId, error) {
if v, ok := parsed.Parsed["thingId"]; true {
if !ok {
return nil, fmt.Errorf("the segment 'thingId' was not found in the resource id %q", input)
return nil, resourceids.NewSegmentNotSpecifiedError(id, "thingId", *parsed)
}
thingId, err := parseThing(v)
Expand All @@ -248,7 +248,7 @@ func ParseConstantOnlyIDInsensitively(input string) (*ConstantOnlyId, error) {
if v, ok := parsed.Parsed["thingId"]; true {
if !ok {
return nil, fmt.Errorf("the segment 'thingId' was not found in the resource id %q", input)
return nil, resourceids.NewSegmentNotSpecifiedError(id, "thingId", *parsed)
}
thingId, err := parseThing(v)
Expand Down

0 comments on commit 9a05e7f

Please sign in to comment.