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

Provide errors from Annotated functions are cryptic #829

Closed
sywhang opened this issue Feb 1, 2022 · 0 comments · Fixed by #844
Closed

Provide errors from Annotated functions are cryptic #829

sywhang opened this issue Feb 1, 2022 · 0 comments · Fixed by #844
Assignees

Comments

@sywhang
Copy link
Contributor

sywhang commented Feb 1, 2022

When we use fx.Annotate to annotate a function but that function runs into an error during provide, it errors out like this:

        writer.go:40: [Fx] Error after options were applied: fx.Provide(fx.Annotate(go.uber.org/fx_test.TestModuleSuccess.func3.2(), fx.ResultTags(["name: \"badLogger\""])) from:
            go.uber.org/fx_test.TestModuleSuccess.func3
                /Users/sungyoon/go/src/github.com/uber-go/fx/module_test.go:89
            testing.tRunner
                /usr/local/go/src/testing/testing.go:1259
            Failed: cannot provide function "reflect".makeFuncStub (/usr/local/go/src/reflect/asm_arm64.s:12): cannot provide *fx_test.Logger from [0].Field0: already provided by "reflect".makeFuncStub (/usr/local/go/src/reflect/asm_arm64.s:12)
        writer.go:40: [Fx] LOGGER       Initialized custom logger from go.uber.org/fx/fxtest.New.func1()
        app.go:46: fx.New failed: fx.Provide(fx.Annotate(go.uber.org/fx_test.TestModuleSuccess.func3.2(), fx.ResultTags(["name: \"badLogger\""])) from:
            go.uber.org/fx_test.TestModuleSuccess.func3
                /Users/sungyoon/go/src/github.com/uber-go/fx/module_test.go:89
            testing.tRunner
                /usr/local/go/src/testing/testing.go:1259
            Failed: cannot provide function "reflect".makeFuncStub (/usr/local/go/src/reflect/asm_arm64.s:12): cannot provide *fx_test.Logger from [0].Field0: already provided by "reflect".makeFuncStub (/usr/local/go/src/reflect/asm_arm64.s:12)

As shown above, the error logs point to [0].Field0: already provided by "reflect".makeFuncStub as where the function was provided from, which can't be easily tracked down cause that's the reflect package's caller frame.

This may be fixed using Dig's LocationForPC ProvideOption.

@sywhang sywhang self-assigned this Feb 1, 2022
@sywhang sywhang changed the title Errors from Annotated Function is cryptic Provide errors from Annotated functions are cryptic Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants