Skip to content

Commit

Permalink
remove dep
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed May 14, 2024
1 parent 337548d commit 010dd44
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
22 changes: 14 additions & 8 deletions depinject/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package depinject

import (
"errors"
"fmt"
"reflect"

pkgerrors "github.com/pkg/errors"
"runtime"

Check notice

Code scanning / CodeQL

Sensitive package import Note

Certain system packages contain functions which may be a possible source of non-determinism
)

// Config is a functional configuration of a container.
Expand Down Expand Up @@ -45,11 +45,11 @@ func provide(ctr *container, key *moduleKey, providers []interface{}) error {
for _, c := range providers {
rc, err := extractProviderDescriptor(c)
if err != nil {
return pkgerrors.WithStack(err)
return fmt.Errorf("%w\n%s", err, getStackTrace())
}
_, err = ctr.addNode(&rc, key)
if err != nil {
return pkgerrors.WithStack(err)
return fmt.Errorf("%w\n%s", err, getStackTrace())
}
}
return nil
Expand Down Expand Up @@ -92,7 +92,7 @@ func invoke(ctr *container, key *moduleKey, invokers []interface{}) error {
for _, c := range invokers {
rc, err := extractInvokerDescriptor(c)
if err != nil {
return errors.WithStack(err)
return fmt.Errorf("%w\n%s", err, getStackTrace())
}
err = ctr.addInvoker(&rc, key)
if err != nil {
Expand Down Expand Up @@ -152,7 +152,7 @@ func Supply(values ...interface{}) Config {
for _, v := range values {
err := ctr.supply(reflect.ValueOf(v), loc)
if err != nil {
return errors.WithStack(err)
return fmt.Errorf("%w\n%s", err, getStackTrace())
}
}
return nil
Expand All @@ -163,7 +163,7 @@ func Supply(values ...interface{}) Config {
// fail immediately.
func Error(err error) Config {
return containerConfig(func(*container) error {
return errors.WithStack(err)
return fmt.Errorf("%w\n%s", err, getStackTrace())
})
}

Expand All @@ -173,7 +173,7 @@ func Configs(opts ...Config) Config {
for _, opt := range opts {
err := opt.apply(ctr)
if err != nil {
return errors.WithStack(err)
return fmt.Errorf("%w\n%s", err, getStackTrace())
}
}
return nil
Expand All @@ -187,3 +187,9 @@ func (c containerConfig) apply(ctr *container) error {
}

var _ Config = (*containerConfig)(nil)

func getStackTrace() string {
var stack [4096]byte
n := runtime.Stack(stack[:], false)
return string(stack[:n])
}
1 change: 0 additions & 1 deletion depinject/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.20
require (
cosmossdk.io/api v0.7.5
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb
google.golang.org/protobuf v1.34.1
Expand Down
2 changes: 0 additions & 2 deletions depinject/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
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/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
Expand Down

0 comments on commit 010dd44

Please sign in to comment.