Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: depinject AutoDebug does not save graphviz file #12297

Merged
merged 9 commits into from
Jun 21, 2022
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this getting called inside inject? shouldn't it have already been called elsewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, because we add the graph to c.visualizers during cfg.onError.applyConfig(cfg) when using OnError.
There was nothing to be generated when it was called before.


// 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