Skip to content

Commit

Permalink
fix output printing in crashed subprocesses
Browse files Browse the repository at this point in the history
  • Loading branch information
rainu committed Jan 27, 2025
1 parent 6711adb commit 1322c49
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 6 additions & 0 deletions config/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ func (p *PrinterConfig) Validate() error {

return nil
}

func (p *PrinterConfig) Close() {
for _, target := range p.Targets {
target.Close()
}
}
5 changes: 1 addition & 4 deletions controller/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,11 @@ func (c *Controller) beforeClose(ctx context.Context) (prevent bool) {

func (c *Controller) Shutdown() {
c.shutdown(c.ctx)
c.appConfig.Printer.Close()
os.Exit(0)
}

func (c *Controller) shutdown(ctx context.Context) {
c.LLMInterrupt()
c.aiModel.Close()

for _, target := range c.appConfig.Printer.Targets {
target.Close()
}
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func main() {
onStartUp(cfg)
}
}
defer cfg.Printer.Close()

ctrl, err := controller.BuildFromConfig(cfg, os.Getenv(lastStateEnv))
if err != nil {
Expand Down Expand Up @@ -95,7 +96,6 @@ func main() {
lastStateEnv: ctrl.GetLastState(),
}

//TODO: dont know why stdout doesnt work properly (os.Stderr would work)
cmdchain.Builder().WithInput(os.Stdin).
Join(os.Args[0], os.Args[1:]...).WithAdditionalEnvironmentMap(ae).
Finalize().WithError(os.Stderr).WithOutput(os.Stdout).
Expand Down

0 comments on commit 1322c49

Please sign in to comment.