What
c.logger is only initialized inside persistentPreRun, which Cobra calls before each command. If a command is invoked programmatically (e.g., runCmd.Run(runCmd, []string{}) directly), c.logger remains nil and calls like c.logger.Trace(...) panic with a nil pointer dereference.
Why
This is a pre-existing issue from before the dependency injection refactor — the package-level logger global had the same nil exposure. The refactor preserved the behavior but did not add a guard.
Suggested fix
Initialize c.logger to a null logger in NewCLI so it's never nil:
c := &CLI{
logger: hclog.NewNullLogger(),
// ...
}
persistentPreRun would still overwrite it with the real logger from config.
What
c.loggeris only initialized insidepersistentPreRun, which Cobra calls before each command. If a command is invoked programmatically (e.g.,runCmd.Run(runCmd, []string{})directly),c.loggerremains nil and calls likec.logger.Trace(...)panic with a nil pointer dereference.Why
This is a pre-existing issue from before the dependency injection refactor — the package-level
loggerglobal had the same nil exposure. The refactor preserved the behavior but did not add a guard.Suggested fix
Initialize
c.loggerto a null logger inNewCLIso it's never nil:persistentPreRunwould still overwrite it with the real logger from config.