Skip to content

Commit 488a555

Browse files
committed
chore: Enhance PopulateResourceFromAnnotation error message
The error message returned from PopulateResourceFromAnnotation was not descriptive enough, as it did not include the name of the required field that was missing. This change is including the field name in the error message.
1 parent 0909e7f commit 488a555

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pkg/generate/code/set_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ func requiredFieldGuardContructor(
858858
indent := strings.Repeat("\t", indentLevel)
859859
out := fmt.Sprintf("%stmp, ok := %s[\"%s\"]\n", indent, sourceVarName, requiredField)
860860
out += fmt.Sprintf("%sif !ok {\n", indent)
861-
out += fmt.Sprintf("%s\treturn ackerrors.MissingNameIdentifier\n", indent)
861+
out += fmt.Sprintf("%s\treturn ackerrors.NewTerminalError(fmt.Errorf(\"required field missing: %s\"))\n", indent, requiredField)
862862
out += fmt.Sprintf("%s}\n", indent)
863863
return out
864864
}

pkg/generate/code/set_resource_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ func TestSetResource_EKS_Cluster_PopulateResourceFromAnnotation(t *testing.T) {
18021802
expected := `
18031803
tmp, ok := fields["name"]
18041804
if !ok {
1805-
return ackerrors.MissingNameIdentifier
1805+
return ackerrors.NewTerminalError(fmt.Errorf("required field missing: name"))
18061806
}
18071807
r.ko.Spec.Name = &tmp
18081808
@@ -1825,7 +1825,7 @@ func TestSetResource_SageMaker_ModelPackage_PopulateResourceFromAnnotation(t *te
18251825
expected := `
18261826
tmp, ok := identifier["arn"]
18271827
if !ok {
1828-
return ackerrors.MissingNameIdentifier
1828+
return ackerrors.NewTerminalError(fmt.Errorf("required field missing: arn"))
18291829
}
18301830
18311831
if r.ko.Status.ACKResourceMetadata == nil {
@@ -1852,7 +1852,7 @@ func TestSetResource_APIGWV2_ApiMapping_PopulateResourceFromAnnotation(t *testin
18521852
expected := `
18531853
tmp, ok := fields["apiMappingID"]
18541854
if !ok {
1855-
return ackerrors.MissingNameIdentifier
1855+
return ackerrors.NewTerminalError(fmt.Errorf("required field missing: apiMappingID"))
18561856
}
18571857
r.ko.Status.APIMappingID = &tmp
18581858

0 commit comments

Comments
 (0)