uber-go/fx

Provide errors from Annotated functions are cryptic

sywhang opened this issue · 0 comments

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.