11package source_mcp
22
33import (
4+ "errors"
45 "fmt"
56 "io"
67 "os/exec"
@@ -28,25 +29,35 @@ type McpCommand struct {
2829}
2930
3031func establishPipeToFile (dst io.WriteCloser , src io.Reader ) {
31- defer dst .Close ()
32+ defer func () {
33+ err := dst .Close ()
34+ if err != nil {
35+ log .Error ("Error closing destination pipe" )
36+ }
37+ }()
3238 _ , err := io .Copy (dst , src )
3339 if err != nil {
3440 log .Error ("Error establishing pipe" )
3541 }
3642}
3743
3844func establishPipeFromFile (dst io.Writer , src io.ReadCloser ) {
39- defer src .Close ()
45+ defer func () {
46+ err := src .Close ()
47+ if err != nil {
48+ log .Error ("Error closing source pipe" )
49+ }
50+ }()
4051 _ , err := io .Copy (dst , src )
4152 if err != nil {
4253 log .Error ("Error establishing pipe" )
4354 }
4455}
4556
46- func RunAmMcpWithPipes (env map [string ]string , cmd string , input_pipe io.Reader , output_pipe io.Writer , error_pipe io.Writer , timeout int , args ... string ) error {
57+ func RunAmMcpWithPipes (env map [string ]string , cmd string , input_pipe io.Reader , output_pipe io.Writer , error_pipe io.Writer , timeout int , args ... string ) ( err error ) {
4758 am_path , err := jas .GetAnalyzerManagerExecutable ()
4859 if err != nil {
49- return err
60+ return
5061 }
5162
5263 allArgs := append ([]string {cmd }, args ... )
@@ -59,21 +70,33 @@ func RunAmMcpWithPipes(env map[string]string, cmd string, input_pipe io.Reader,
5970 log .Error (fmt .Sprintf ("Error creating MCPService stdin pipe: %v" , _error ))
6071 return _error
6172 }
62- defer stdin .Close ()
73+ defer func () {
74+ if _error := stdin .Close (); _error != nil {
75+ err = errors .Join (err , fmt .Errorf ("error closing MCPService stdin pipe: %v" , _error ))
76+ }
77+ }()
6378
6479 stdout , _error := command .StdoutPipe ()
6580 if _error != nil {
6681 log .Error (fmt .Sprintf ("Error creating MCPService stdout pipe: %v" , _error ))
6782 return _error
6883 }
69- defer stdout .Close ()
84+ defer func () {
85+ if _error := stdout .Close (); _error != nil {
86+ err = errors .Join (err , fmt .Errorf ("error closing MCPService stdout pipe: %v" , _error ))
87+ }
88+ }()
7089
7190 stderr , _error := command .StderrPipe ()
7291 if _error != nil {
7392 log .Error (fmt .Sprintf ("Error creating MCPService stderr pipe: %v" , _error ))
7493 return _error
7594 }
76- defer stderr .Close ()
95+ defer func () {
96+ if _error := stderr .Close (); _error != nil {
97+ err = errors .Join (err , fmt .Errorf ("error closing MCPService stderr pipe: %v" , _error ))
98+ }
99+ }()
77100
78101 go establishPipeToFile (stdin , input_pipe )
79102 go establishPipeFromFile (error_pipe , stderr )
0 commit comments