fix: clean the subnet not-found message and name the subnet ID in DeleteSubnet and DescribeSubnets

This commit is contained in:
Julian Sommer
2026-09-30 10:14:58 +10:00
parent 5f60b2c7c7
commit f67a326b97
3 changed files with 22 additions and 7 deletions
+1 -1
View File
@@ -1069,7 +1069,7 @@ var ErrorLookup = map[string]ErrorMessage{
ErrorInvalidSubnetConflict: {HTTPCode: 409, Message: "The specified CIDR block conflicts with that of another subnet in your VPC."},
ErrorInvalidSubnetRange: {HTTPCode: 400, Message: "The CIDR block you've specified for the subnet is not valid. The allowed block size is between a /28 netmask and /16 netmask."},
ErrorInvalidSubnetIDMalformed: {HTTPCode: 400, Message: "The specified subnet ID is malformed. Ensure that you specify the ID in the form subnet-xxxxxxxxxxxxxxxxx"},
ErrorInvalidSubnetIDNotFound: {HTTPCode: 404, Message: "or InvalidSubnetId.NotFound \tThe specified subnet does not exist."},
ErrorInvalidSubnetIDNotFound: {HTTPCode: 404, Message: "The specified subnet does not exist."},
ErrorInvalidTagKeyMalformed: {HTTPCode: 400, Message: "The specified tag key is not valid. Tag keys cannot be empty or null, and cannot start with aws:."},
ErrorInvalidTargetArnUnknown: {HTTPCode: 404, Message: "The specified ARN for the specified user or role is not valid or does not exist."},
ErrorInvalidTargetException: {HTTPCode: 404, Message: "The specified TargetId is not valid, does not exist, or is in another organization. You can only generate an account status report for declarative policies in your own organization. Ensure that you specify the TargetId in one of the following forms: r-xxxx, ou-xxxx-xxxxxxxx, or a 12-digit account ID in the form xxxxxxxxxxxx."},
+4 -4
View File
@@ -811,7 +811,7 @@ func (s *VPCServiceImpl) DeleteSubnet(ctx context.Context, input *ec2.DeleteSubn
// destroy); destroy orchestration tolerates it too. A transient read
// error stays a server error.
if errors.Is(err, jetstream.ErrKeyNotFound) {
return nil, errors.New(awserrors.ErrorInvalidSubnetIDNotFound)
return nil, awserrors.Errorf(awserrors.ErrorInvalidSubnetIDNotFound, "The subnet ID '%s' does not exist", subnetID)
}
return nil, errors.New(awserrors.ErrorServerInternal)
}
@@ -1044,9 +1044,9 @@ func (s *VPCServiceImpl) DescribeSubnets(ctx context.Context, input *ec2.Describ
found[*subnet.SubnetId] = true
}
}
for id := range subnetIDs {
if !found[id] {
return nil, errors.New(awserrors.ErrorInvalidSubnetIDNotFound)
for _, id := range input.SubnetIds {
if id != nil && !found[*id] {
return nil, awserrors.Errorf(awserrors.ErrorInvalidSubnetIDNotFound, "The subnet ID '%s' does not exist", *id)
}
}
}
+17 -2
View File
@@ -511,9 +511,24 @@ func TestDescribeSubnets_NotFound(t *testing.T) {
t.Parallel()
svc := setupTestVPCService(t)
_, err := svc.DescribeSubnets(context.Background(), &ec2.DescribeSubnetsInput{
SubnetIds: []*string{aws.String("subnet-nonexistent")},
SubnetIds: []*string{aws.String("subnet-missing1"), aws.String("subnet-missing2")},
}, testAccountID)
assert.ErrorContains(t, err, "InvalidSubnetID.NotFound")
code, msg, ok := awserrors.ResolveErrorDetail(err)
require.True(t, ok, "error %v carries no AWS code", err)
assert.Equal(t, awserrors.ErrorInvalidSubnetIDNotFound, code)
assert.Equal(t, "The subnet ID 'subnet-missing1' does not exist", msg)
}
func TestDeleteSubnet_NotFound(t *testing.T) {
t.Parallel()
svc := setupTestVPCService(t)
_, err := svc.DeleteSubnet(context.Background(), &ec2.DeleteSubnetInput{
SubnetId: aws.String("subnet-missing1"),
}, testAccountID)
code, msg, ok := awserrors.ResolveErrorDetail(err)
require.True(t, ok, "error %v carries no AWS code", err)
assert.Equal(t, awserrors.ErrorInvalidSubnetIDNotFound, code)
assert.Equal(t, "The subnet ID 'subnet-missing1' does not exist", msg)
}
func TestCreateMultipleSubnetsInVpc(t *testing.T) {