Skip to content

Commit

Permalink
Handle errors in python subprocess cmd.Start() (#27986)
Browse files Browse the repository at this point in the history
  • Loading branch information
gh123man authored Jul 26, 2024
1 parent 5cafc93 commit ab2f289
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/collector/python/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func testGetSubprocessOutputUnknownBin(t *testing.T) {
assert.Equal(t, "", C.GoString(cStdout))
assert.Equal(t, "", C.GoString(cStderr))
assert.Equal(t, C.int(0), cRetCode)
assert.Nil(t, exception)
assert.NotNil(t, exception)
}

func testGetSubprocessOutputError(t *testing.T) {
Expand Down
6 changes: 5 additions & 1 deletion pkg/collector/python/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ func GetSubprocessOutput(argv **C.char, env **C.char, cStdout **C.char, cStderr
outputErr, _ = io.ReadAll(stderr)
}()

cmd.Start() //nolint:errcheck
err = cmd.Start()
if err != nil {
*exception = TrackedCString(fmt.Sprintf("internal error starting subprocess: %v", err))
return
}

// Wait for the pipes to be closed *before* waiting for the cmd to exit, as per os.exec docs
wg.Wait()
Expand Down

0 comments on commit ab2f289

Please sign in to comment.