44 "context"
55 "io/fs"
66
7+ "github.com/livebud/bud/internal/errs"
78 "github.com/livebud/bud/internal/exe"
89 "github.com/livebud/bud/internal/extrafile"
910 "github.com/livebud/bud/internal/once"
@@ -24,28 +25,31 @@ func (c *Command) Start(ctx context.Context, name string, args ...string) (*Proc
2425 if err != nil {
2526 return nil , err
2627 }
27- closer .Closes = append ( closer . Closes , ln .Close )
28+ closer .Add ( ln .Close )
2829 // Turn the listener into a file to be passed to the subprocess
2930 file , err := ln .File ()
3031 if err != nil {
31- return nil , closer .Close (err )
32+ err = errs .Join (err , closer .Close ())
33+ return nil , err
3234 }
33- closer .Closes = append ( closer . Closes , file .Close )
35+ closer .Add ( file .Close )
3436 // Inject the file listener into the subprocess
3537 extrafile .Inject (& c .ExtraFiles , & c .Env , defaultPrefix , file )
3638 // Start the subprocess
3739 process , err := (* exe .Command )(c ).Start (ctx , name , args ... )
3840 if err != nil {
39- return nil , closer .Close (err )
41+ err = errs .Join (err , closer .Close ())
42+ return nil , err
4043 }
41- closer .Closes = append ( closer . Closes , process .Close )
44+ closer .Add ( process .Close )
4245 // Dial the subprocess and return a client
4346 addr := ln .Addr ().String ()
4447 client , err := Dial (ctx , addr )
4548 if err != nil {
46- return nil , closer .Close (err )
49+ err = errs .Join (err , closer .Close ())
50+ return nil , err
4751 }
48- closer .Closes = append ( closer . Closes , client .Close )
52+ closer .Add ( client .Close )
4953 // Return the process
5054 return & Process {client , & closer , process , addr }, nil
5155}
0 commit comments