aws / aws-sdk

Landing page for the AWS SDKs on GitHub
https://aws.amazon.com/tools/
Other
68 stars 12 forks source link

Message is not set when ValidationException is returned in PutInlinePolicyToPermissionSet. #678

Open miyajan opened 5 months ago

miyajan commented 5 months ago

Describe the bug

I want to get Mesage when ValidationException occurs in PutInlinePolicyToPermissionSet function, but I can't get it.

Expected Behavior

I get ValidationException: <Error Message> when I run the following code

    err := client.PutInlinePolicyToPermissionSet(permissionSetArn, inlinePolicy)
    if err != nil {
        var validationException *types.ValidationException
        if errors.As(err, &validationException) {
            log.Println("error: %s", validationException.Error())
        }
    }

Current Behavior

Only ValidationException: is displayed.

Reproduction Steps

As written in Expected Behavior.

Possible Solution

Looking at the response body, the ValidationException message is returned with a key message, but the generated code checks Message. https://github.com/aws/aws-sdk-go-v2/blob/a7db10670faedd542dc92cec6d0c602e5315a3a9/service/ssoadmin/deserializers.go#L12484

Additional Information/Context

No response

AWS Go SDK V2 Module Versions Used

module github.com/cybozu-ept/aws-sso-permission-set-updater

go 1.21

require (
    github.com/aws/aws-sdk-go-v2/config v1.26.3
    github.com/aws/aws-sdk-go-v2/service/ssoadmin v1.23.6
)

require (
    github.com/aws/aws-sdk-go-v2 v1.24.1 // indirect
    github.com/aws/aws-sdk-go-v2/credentials v1.16.14 // indirect
    github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.11 // indirect
    github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10 // indirect
    github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10 // indirect
    github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2 // indirect
    github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 // indirect
    github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.10 // indirect
    github.com/aws/aws-sdk-go-v2/service/sso v1.18.6 // indirect
    github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.6 // indirect
    github.com/aws/aws-sdk-go-v2/service/sts v1.26.7 // indirect
    github.com/aws/smithy-go v1.19.0 // indirect
)

Compiler and Version used

go version go1.21.5 darwin/arm64

Operating System and version

macOS 14.1

RanVaknin commented 5 months ago

Hi @miyajan ,

I think I see the issue here.

The the SSO Admin API model specifies the error field Message (upper case) but returns message (in lower case) this mismatch will cause the deserializer logic to not get a match between the incoming data and expected shape and would explain the omission.

I have created a ticket with the SSO team to address this discrepancy. In the meantime, if you are just looking to inspect the raw response coming back from the service and bypass the deserialization, you can enable the response logging:

func main() {
    cfg, err := config.LoadDefaultConfig(
        context.TODO(),
        config.WithRegion("us-east-1"),
        config.WithClientLogMode(aws.LogResponseWithBody),
    )
    if err != nil {
        log.Fatalf("unable to load SDK config, %v", err)
    }

I'll transfer this issue to the cross-SDK repo and will update you there once I hear back from the SSO service team.

Thanks again, Ran~

P113857014