From 52307b41bf985b782c5362459ad37656020e62ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Wed, 10 Jul 2024 17:06:27 +0800 Subject: [PATCH] add provider stack log (#16) --- go.mod | 5 +++-- go.sum | 17 +++++++++-------- internal/dix_inter/dix.go | 14 +++++++++++++- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 2b95722..f125ca6 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/pubgo/dix go 1.19 -require github.com/pubgo/funk v0.5.40 +require github.com/pubgo/funk v0.5.46 require ( github.com/alecthomas/repr v0.2.0 // indirect @@ -12,8 +12,9 @@ require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/phuslu/goid v1.0.0 // indirect - github.com/rs/zerolog v1.30.0 // indirect + github.com/rs/zerolog v1.33.0 // indirect golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb // indirect + golang.org/x/net v0.21.0 // indirect golang.org/x/sys v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/genproto v0.0.0-20221027153422-115e99e71e1c // indirect diff --git a/go.sum b/go.sum index aefd89c..9d0ce5a 100644 --- a/go.sum +++ b/go.sum @@ -10,10 +10,8 @@ github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6 github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/k0kubun/pp/v3 v3.2.0 h1:h33hNTZ9nVFNP3u2Fsgz8JXiF5JINoZfFq4SvKJwNcs= github.com/k0kubun/pp/v3 v3.2.0/go.mod h1:ODtJQbQcIRfAD3N+theGCV1m/CBxweERz2dapdz1EwA= -github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= @@ -21,20 +19,23 @@ github.com/phuslu/goid v1.0.0 h1:Cgcvd/R54UO1fCtyt+iKXAi+yZQ/KWlAm6MmZNizCLM= github.com/phuslu/goid v1.0.0/go.mod h1:txc2fUIdrdnn+v9Vq+QpiPQ3dnrXEchjoVDgic+r+L0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pubgo/funk v0.5.40 h1:uLN637YY/ljykp5R+bmBGl47wMzsUENW/ZvYG1APNGE= -github.com/pubgo/funk v0.5.40/go.mod h1:gKCw72+MK7xPiUGY1Z/bdGJMrSfVi87r0x/7d1GtKU4= +github.com/pubgo/funk v0.5.46 h1:UoEW7vm0Iy2c73wMq/wYM6NVEg/ZPpxDaJhobCvbGeI= +github.com/pubgo/funk v0.5.46/go.mod h1:Hm4oOYENrlr8A8nuH2YQWdx5jGg1fjAjaTvN2I28ts4= github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c= -github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w= +github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= +github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb h1:mIKbk8weKhSeLH2GmUTrvx8CjkyJmnU1wFmg59CUjFA= golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= diff --git a/internal/dix_inter/dix.go b/internal/dix_inter/dix.go index 4a611d2..a701602 100644 --- a/internal/dix_inter/dix.go +++ b/internal/dix_inter/dix.go @@ -9,6 +9,7 @@ import ( "github.com/pubgo/funk/errors" "github.com/pubgo/funk/log" "github.com/pubgo/funk/recovery" + "github.com/pubgo/funk/stack" ) func newDix(opts ...Option) *Dix { @@ -121,6 +122,14 @@ func (x *Dix) evalProvider(typ outputType, opt Options) map[group][]value { return x.objects[typ] } +func (x *Dix) getProviderStack(typ reflect.Type) []string { + var stacks []string + for _, n := range x.providers[typ] { + stacks = append(stacks, stack.CallerWithFunc(n.fn).String()) + } + return stacks +} + func (x *Dix) getValue(typ reflect.Type, opt Options, isMap, isList bool) reflect.Value { switch { case isMap: @@ -128,8 +137,8 @@ func (x *Dix) getValue(typ reflect.Type, opt Options, isMap, isList bool) reflec if !opt.AllowValuesNull && len(valMap) == 0 { log.Panic(). Any("options", opt). - Any("values", valMap). Str("type", typ.String()). + Any("providers", x.getProviderStack(typ)). Str("type-kind", typ.Kind().String()). Msg("provider value not found") } @@ -146,6 +155,7 @@ func (x *Dix) getValue(typ reflect.Type, opt Options, isMap, isList bool) reflec log.Panic().Err(err). Any("options", opt). Any("values", valMap[defaultKey]). + Any("providers", x.getProviderStack(typ)). Str("type", typ.String()). Str("type-kind", typ.Kind().String()). Msg(err.Msg) @@ -163,6 +173,7 @@ func (x *Dix) getValue(typ reflect.Type, opt Options, isMap, isList bool) reflec Any("options", opt). Any("values", valMap[defaultKey]). Str("type", typ.String()). + Any("providers", x.getProviderStack(typ)). Str("type-kind", typ.Kind().String()). Msg("provider value not found") } else { @@ -177,6 +188,7 @@ func (x *Dix) getValue(typ reflect.Type, opt Options, isMap, isList bool) reflec log.Panic().Err(err). Any("options", opt). Any("values", valList). + Any("providers", x.getProviderStack(typ)). Str("type", typ.String()). Str("type-kind", typ.Kind().String()). Msg(err.Msg)