44 "bytes"
55 "errors"
66 "fmt"
7- "go.flow.arcalot.io/pythondeployer/internal/models"
87 "go.arcalot.io/log/v2"
8+ "go.flow.arcalot.io/pythondeployer/internal/models"
99 "io"
1010 "os"
1111 "os/exec"
@@ -14,10 +14,11 @@ import (
1414)
1515
1616type cliWrapper struct {
17- pythonFullPath string
18- workDir string
19- deployCommand * exec.Cmd
20- logger log.Logger
17+ pythonFullPath string
18+ workDir string
19+ deployCommand * exec.Cmd
20+ logger log.Logger
21+ stdErrBuff bytes.Buffer
2122}
2223
2324const RunnableClassifier string = "Arcaflow :: Python Deployer :: Runnable"
@@ -27,9 +28,9 @@ func NewCliWrapper(pythonFullPath string,
2728 logger log.Logger ,
2829) CliWrapper {
2930 return & cliWrapper {
30- pythonFullPath : pythonFullPath ,
31- logger : logger ,
32- workDir : workDir ,
31+ pythonFullPath : pythonFullPath ,
32+ logger : logger ,
33+ workDir : workDir ,
3334 }
3435}
3536
@@ -76,6 +77,7 @@ func (p *cliWrapper) ModuleExists(fullModuleName string) (*bool, error) {
7677 }
7778
7879 if _ , err := os .Stat (* modulePath ); os .IsNotExist (err ) {
80+ // false
7981 return & moduleExists , nil
8082 }
8183
@@ -111,7 +113,7 @@ func (p *cliWrapper) PullModule(fullModuleName string) error {
111113 var cmdCreateOut bytes.Buffer
112114 cmdCreateVenv .Stderr = & cmdCreateOut
113115 if err := cmdCreateVenv .Run (); err != nil {
114- return errors . New ( cmdCreateOut .String ())
116+ return fmt . Errorf ( "error while creating venv. Stderr: '%s', err: '%s'" , cmdCreateOut .String (), err )
115117 }
116118
117119 // pull module
@@ -120,7 +122,7 @@ func (p *cliWrapper) PullModule(fullModuleName string) error {
120122 var cmdPipOut bytes.Buffer
121123 cmdPip .Stderr = & cmdPipOut
122124 if err := cmdPip .Run (); err != nil {
123- return errors . New ( cmdPipOut .String ())
125+ return fmt . Errorf ( "error while running pip. stderr: '%s', err: '%s'" , cmdPipOut .String (), err )
124126 }
125127 return nil
126128}
@@ -141,8 +143,7 @@ func (p *cliWrapper) Deploy(fullModuleName string) (io.WriteCloser, io.ReadClose
141143 venvPython := fmt .Sprintf ("%s/venv/bin/python" , * venvPath )
142144
143145 p .deployCommand = exec .Command (venvPython , args ... ) //nolint:gosec
144- var stdErrBuff bytes.Buffer
145- p .deployCommand .Stderr = & stdErrBuff
146+ p .deployCommand .Stderr = & p .stdErrBuff
146147 stdin , err := p .deployCommand .StdinPipe ()
147148 if err != nil {
148149 return nil , nil , err
@@ -153,12 +154,17 @@ func (p *cliWrapper) Deploy(fullModuleName string) (io.WriteCloser, io.ReadClose
153154 }
154155
155156 if err := p .deployCommand .Start (); err != nil {
156- return nil , nil , errors . New ( stdErrBuff .String ())
157+ return nil , nil , fmt . Errorf ( "error while attempting to run python stderr: '%s', err: '%s'" , p . stdErrBuff .String (), err . Error ())
157158 }
158159 return stdin , stdout , nil
159160}
160161
161162func (p * cliWrapper ) KillAndClean () error {
163+ if p .stdErrBuff .Len () > 0 {
164+ p .logger .Errorf ("stderr present after plugin execution: %s" , p .stdErrBuff .String ())
165+ } else {
166+ p .logger .Infof ("stderr empty" )
167+ }
162168 p .logger .Infof ("killing config process with pid %d" , p .deployCommand .Process .Pid )
163169 err := p .deployCommand .Process .Kill ()
164170 if err != nil {
0 commit comments