fx.ValidateApp fails on a valid graph when using fx.Decorate
vladimir-gavrilenko opened this issue · 2 comments
vladimir-gavrilenko commented
Describe the bug
Functions inside fx.Decorate
are invoked with nil
s 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
JacobOaks commented
Thanks for reporting this. I've reproduced the panic and will look into it.
sywhang commented
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.