uber-go/fx

fx.ValidateApp fails on a valid graph when using fx.Decorate

vladimir-gavrilenko opened this issue · 2 comments

Describe the bug
Functions inside fx.Decorate are invoked with nils as required parameters when calling fx.ValidateApp.

To Reproduce
If I take a snippet from the docs, and make a unit test, fx.ValidateApp will panic.

func TestDecoratorScope(t *testing.T) {
	opts := fx.Options(
		fx.Module("mymodule",
			fx.Decorate(func(log *zap.Logger) *zap.Logger {
				return log.Named("myapp")
			}),
			fx.Invoke(func(log *zap.Logger) {
				log.Info("decorated logger")
				// Output:
				// {"level": "info","logger":"myapp","msg":"decorated logger"}
			}),
		),
		fx.Invoke(func(log *zap.Logger) {
			log.Info("plain logger")
			// Output:
			// {"level": "info","msg":"plain logger"}
		}),
		fx.Provide(zap.NewProduction),
	)

	// uncomment the line below to panic
	// assert.NoError(t, fx.ValidateApp(opts))
	app := fxtest.New(t, opts)
	app.RequireStart().RequireStop()
}

Expected behavior
If an app can run, fx.ValidateApp should not cause a panic.

Additional context
n/a

Thanks for reporting this. I've reproduced the panic and will look into it.

This issue was fixed in Dig. If you update your dependency to the latest version of Dig (v1.16.1), that should address the issue.