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

Unexpected error type returned for DescribeDBClusterParameterGroups #2661

Closed
2 tasks done
jayjanssen opened this issue May 31, 2024 · 4 comments
Closed
2 tasks done
Assignees
Labels
bug This issue is a bug. service-api This issue is due to a problem in a service API, not the SDK implementation.

Comments

@jayjanssen
Copy link

Acknowledgements

Describe the bug

When calling DescribeDBClusterParameterGroups with a DBClusterParameterGroupName that does not exist, the error returned isDBParameterGroupNotFoundFault, but I would expect a DBClusterParameterGroupNotFoundFault.

Expected Behavior

I would expect the error returned would be a DBClusterParameterGroupNotFoundFault type

Current Behavior

The error type returned is DBParameterGroupNotFoundFault, which is for instance parameter groups, not cluster parameter groups.

The reproduction code below yields this output:

~/tmp/error-bug go run .
2024/05/31 08:16:18 Got unexpected DBParameterGroupNotFoundFault error
exit status 1

Reproduction Steps

package main

import (
	"context"
	"errors"
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/credentials"
	"github.com/aws/aws-sdk-go-v2/service/rds"
	"github.com/aws/aws-sdk-go-v2/service/rds/types"
)

func main() {
	var cfgOpts []func(*config.LoadOptions) error

	envCfg, err := config.NewEnvConfig()
	if err != nil {
		log.Fatalln("Failed to retrieve AWS configuration from environment", err.Error())
	}

	if awsRegion := envCfg.Region; awsRegion != "" {
		cfgOpts = append(cfgOpts, config.WithRegion(awsRegion))
	}

	var credsProvider aws.CredentialsProvider
	credsProvider = credentials.NewStaticCredentialsProvider(
		envCfg.Credentials.AccessKeyID,
		envCfg.Credentials.SecretAccessKey,
		envCfg.Credentials.SessionToken,
	)

	cfgOpts = append(cfgOpts, config.WithCredentialsProvider(credsProvider))

	ctx := context.Background()

	// Setup AWS configuration
	awsCfg, err := config.LoadDefaultConfig(ctx, cfgOpts...)
	if err != nil {
		log.Fatalln("AWS Configuration Error", err.Error())
	}

	rdsClient := rds.NewFromConfig(awsCfg)

	pgName := "not-a-real-db-cluster-parameter-group-name"

	input := &rds.DescribeDBClusterParameterGroupsInput{
		DBClusterParameterGroupName: aws.String(pgName),
	}

	_, err = rdsClient.DescribeDBClusterParameterGroups(ctx, input)
	if err == nil {
		log.Fatalf("Expected an error, got none")
	}

	var clusterPgNotFoundErr *types.DBClusterParameterGroupNotFoundFault
	var instancePgNotFoundErr *types.DBParameterGroupNotFoundFault
	if errors.As(err, &clusterPgNotFoundErr) {
		log.Print("Got expected DBClusterParameterGroupNotFoundFault error")
	} else if errors.As(err, &instancePgNotFoundErr) {
		log.Fatalln("Got unexpected DBParameterGroupNotFoundFault error")
	} else {
		log.Fatalf("Got totally unexpected error: %s", err.Error())
	}

}

Possible Solution

No response

Additional Information/Context

No response

AWS Go SDK V2 Module Versions Used

	github.com/aws/aws-sdk-go-v2 v1.27.0 // indirect
	github.com/aws/aws-sdk-go-v2/config v1.27.16 // indirect
	github.com/aws/aws-sdk-go-v2/credentials v1.17.16 // indirect
	github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.3 // indirect
	github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.7 // indirect
	github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.7 // indirect
	github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.9 // indirect
	github.com/aws/aws-sdk-go-v2/service/rds v1.79.3 // indirect
	github.com/aws/aws-sdk-go-v2/service/sso v1.20.9 // indirect
	github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.3 // indirect
	github.com/aws/aws-sdk-go-v2/service/sts v1.28.10 // indirect

Compiler and Version used

go version go1.22.1 darwin/arm64

Operating System and version

Darwin blklfvq104fww.local 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:17:33 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6031 arm64

@jayjanssen jayjanssen added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 31, 2024
@RanVaknin
Copy link
Contributor

Hi @jayjanssen,

Thanks for reaching out.

The error returned here is not controlled by the SDK, this is a server error and while I agree that DBClusterParameterGroupNotFoundFault SHOULD be returned when querying a cluster parameter group, the service team chose to both model and return the error as DBParameterGroupNotFoundFault indicating that this is the actual expected returned error (even though this might have been an oversight)

You can look at the API docs for DescribeDBClusterParameterGroups and the external model file from which the SDK is generated from and see that the only modeled exception, and also the one that is returned is in fact DBParameterGroupNotFound.

So while I agree that this confusing, there is nothing the SDK team can do about it. From an API perspective, this is an exception that was modeled (and returned) incorrectly for 4 years. So if customers are error handling on this incorrect exception, by changing the type returned from the backend, we risk breaking customers that depend on that incorrect behavior.

Thanks again for reaching out. I hope you can make this work.
All the best,
Ran~

@RanVaknin RanVaknin self-assigned this May 31, 2024
@RanVaknin RanVaknin added service-api This issue is due to a problem in a service API, not the SDK implementation. and removed needs-triage This issue or PR still needs to be triaged. labels May 31, 2024
@RanVaknin RanVaknin closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 2024
Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

@jayjanssen
Copy link
Author

thanks @RanVaknin , this makes sense.

I wonder if this could be documented with the type as a warning to future error type explorers?
https://github.com/aws/aws-sdk-go-v2/blob/main/service/rds/types/errors.go#L558

@RanVaknin
Copy link
Contributor

Hi @jayjanssen ,

The documentation is generated from that same model. In order to submit API specific documentation requests you should use the Feedback button on the top right of each AWS Doc page or by clicking here

Thanks,
Ran~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. service-api This issue is due to a problem in a service API, not the SDK implementation.
Projects
None yet
Development

No branches or pull requests

2 participants