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

bug(go): Using Aspects causes panic: Call using *awscdk.IConstruct as type awscdk.IConstruct #2793

Closed
1 of 5 tasks
corymhall opened this issue Apr 14, 2021 · 4 comments · Fixed by #2797
Closed
1 of 5 tasks
Assignees
Labels
bug This issue is a bug. effort/small Small work item – less than a day of effort language/go Regarding GoLang bindings module/runtime Issues affecting the `jsii-runtime` p1

Comments

@corymhall
Copy link
Contributor

🐛 Bug Report

Affected Languages

  • TypeScript or Javascript
  • Python
  • Java
  • .NET (C#, F#, ...)
  • Go

General Information

  • JSII Version: v1.28.0
  • Platform: 18.04.1-Ubuntu

What is the problem?

I am trying to use Aspects with the go CDK and I get the below error when running synth:

panic: reflect: Call using *awscdk.IConstruct as type awscdk.IConstruct

goroutine 1 [running]:
github.com/aws/jsii-runtime-go.Invoke(0x6e8de0, 0xc00009a270, 0x70535b, 0x5, 0xc0002a7ec8, 0x1, 0x1, 0x6900c0, 0xc0000a68a0)
        /home/ubuntu/environment/cdk/cdk-project-go/vendor/github.com/aws/jsii-runtime-go/runtime.go:216 +0x2b7
github.com/aws/aws-cdk-go/awscdk.(*jsiiProxy_App).Synth(0xc00009a270, 0x0, 0x70992e, 0x11)
        /home/ubuntu/environment/cdk/cdk-project-go/vendor/github.com/aws/aws-cdk-go/awscdk/awscdk.go:395 +0xb5
main.main()
        /home/ubuntu/environment/cdk/cdk-project-go/cdk-project-go.go:52 +0xfa
exit status 2

I was able to reproduce the issue with the default app that is created via cdk init --language=go app

Here is my code:

type Aspect struct{}

func (a *Aspect) Visit(node awscdk.IConstruct) {
        awscdk.Annotations_Of(node).AddInfo(jsii.String("Hello"))
}

type CdkProjectGoStackProps struct {
        awscdk.StackProps
}

func NewCdkProjectGoStack(scope constructs.Construct, id string, props *CdkProjectGoStackProps) awscdk.Stack {
        var sprops awscdk.StackProps
        if props != nil {
                sprops = props.StackProps
        }
        stack := awscdk.NewStack(scope, &id, &sprops)
        
        // The code that defines your stack goes here

        // as an example, here's how you would define an AWS SNS topic:
        awssns.NewTopic(stack, jsii.String("MyTopic"), &awssns.TopicProps{
                DisplayName: jsii.String("MyCoolTopic"),
        })

        return stack
}

func main() {
        app := awscdk.NewApp(nil)

        myStack := NewCdkProjectGoStack(app, "CdkProjectGoStack", &CdkProjectGoStackProps{
                awscdk.StackProps{
                        Env: env(),
                },
        })

        aspect := &Aspect{}

        awscdk.Aspects_Of(myStack).Add(aspect)


        app.Synth(nil)
}

Verbose Log

@corymhall corymhall added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 14, 2021
@RomainMuller
Copy link
Contributor

@all-contributors add @corymhall for bug

@allcontributors
Copy link
Contributor

@RomainMuller

I've put up a pull request to add @corymhall! 🎉

@RomainMuller
Copy link
Contributor

Thanks for reporting this! I have been able to reproduce this, and have identified a fix for that. I'll submit a PR shortly (a draft, though - as I still have to write a test that covers the previously broken case).

RomainMuller added a commit that referenced this issue Apr 15, 2021
The callback handling logic was incorrectly handling "pure" interface
parameters. The reflection piece would create a new argument value in
preparation for the callback, however for interfaces, it would leave the
pointer to the interface type (as returned by `reflect.New`) instead of
indirecting to the interface itself as appropriate.

Fixes #2793
@RomainMuller RomainMuller added effort/small Small work item – less than a day of effort language/go Regarding GoLang bindings module/runtime Issues affecting the `jsii-runtime` p1 and removed needs-triage This issue or PR still needs to be triaged. labels Apr 15, 2021
RomainMuller added a commit that referenced this issue Apr 16, 2021
The callback handling logic was incorrectly handling "pure" interface
parameters. The reflection piece would create a new argument value in
preparation for the callback, however for interfaces, it would leave the
pointer to the interface type (as returned by `reflect.New`) instead of
indirecting to the interface itself as appropriate.

Fixes #2793
RomainMuller added a commit that referenced this issue Apr 16, 2021
The callback handling logic was incorrectly handling "pure" interface
parameters. The reflection piece would create a new argument value in
preparation for the callback, however for interfaces, it would leave the
pointer to the interface type (as returned by `reflect.New`) instead of
indirecting to the interface itself as appropriate.

Fixes #2793
RomainMuller added a commit that referenced this issue Apr 16, 2021
The callback handling logic was incorrectly handling "pure" interface
parameters. The reflection piece would create a new argument value in
preparation for the callback, however for interfaces, it would leave the
pointer to the interface type (as returned by `reflect.New`) instead of
indirecting to the interface itself as appropriate.

Fixes #2793
@mergify mergify bot closed this as completed in #2797 Apr 20, 2021
mergify bot pushed a commit that referenced this issue Apr 20, 2021
The callback handling logic was incorrectly handling "pure" interface
parameters. The reflection piece would create a new argument value in
preparation for the callback, however for interfaces, it would leave the
pointer to the interface type (as returned by `reflect.New`) instead of
indirecting to the interface itself as appropriate.

Fixes #2793



---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

mergify bot pushed a commit that referenced this issue Apr 26, 2021
Adds @corymhall as a contributor for bug.

This was requested by RomainMuller [in this comment](#2793 (comment))
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. effort/small Small work item – less than a day of effort language/go Regarding GoLang bindings module/runtime Issues affecting the `jsii-runtime` p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants