Skip to content

Commit

Permalink
fix: depinject AutoDebug does not save graphviz file (#12297)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Jun 21, 2022
1 parent 2d442b7 commit bd31b7c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
7 changes: 2 additions & 5 deletions depinject/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ func Logger(logger func(string)) DebugOption {
})
}

const (
debugContainerDot = "debug_container.dot"
)
const debugContainerDot = "debug_container.dot"

// Debug is a default debug option which sends log output to stderr, dumps
// the container in the graphviz DOT and SVG formats to debug_container.dot
Expand Down Expand Up @@ -155,8 +153,7 @@ func deleteIfExists(filename string) {
func DebugOptions(options ...DebugOption) DebugOption {
return debugOption(func(c *debugConfig) error {
for _, opt := range options {
err := opt.applyConfig(c)
if err != nil {
if err := opt.applyConfig(c); err != nil {
return err
}
}
Expand Down
28 changes: 13 additions & 15 deletions depinject/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,38 @@ func inject(loc Location, debugOpt DebugOption, config Config, outputs ...interf
return err
}

// always generate graph on exit
defer cfg.generateGraph()

// debug cleanup
defer func() {
for _, f := range cfg.cleanup {
f()
}
}()

err = doInject(cfg, loc, debugOpt, config, outputs...)
if err != nil {
if err = doInject(cfg, loc, debugOpt, config, outputs...); err != nil {
cfg.logf("Error: %v", err)
if cfg.onError != nil {
err2 := cfg.onError.applyConfig(cfg)
if err2 != nil {
if err2 := cfg.onError.applyConfig(cfg); err2 != nil {
return err2
}
}

return err
} else {
if cfg.onSuccess != nil {
err2 := cfg.onSuccess.applyConfig(cfg)
if err2 != nil {
return err2
}
}

if cfg.onSuccess != nil {
if err2 := cfg.onSuccess.applyConfig(cfg); err2 != nil {
return err2
}
return nil
}
return nil
}

func doInject(cfg *debugConfig, loc Location, debugOpt DebugOption, config Config, outputs ...interface{}) error {
defer cfg.generateGraph() // always generate graph on exit

if debugOpt != nil {
err := debugOpt.applyConfig(cfg)
if err != nil {
if err := debugOpt.applyConfig(cfg); err != nil {
return err
}
}
Expand Down

0 comments on commit bd31b7c

Please sign in to comment.