Skip to content

Commit

Permalink
cargo: Dump stderr on compilation error
Browse files Browse the repository at this point in the history
  • Loading branch information
matevz committed Oct 10, 2024
1 parent 6e2926c commit 5e43015
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion build/cargo/cargo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package cargo

import (
"bytes"
"encoding/json"
"fmt"
"os/exec"
Expand Down Expand Up @@ -64,10 +65,14 @@ func Build(release bool, target string, features []string) (string, error) {
args = append(args, "--message-format", "json")

cmd := exec.Command("cargo", args...)
// Parse stdout JSON messages and store stderr to buffer.
stdout, err := cmd.StdoutPipe()
if err != nil {
return "", fmt.Errorf("failed to initialize build process: %w", err)
}
var stderr bytes.Buffer
cmd.Stderr = &stderr

if err = cmd.Start(); err != nil {
return "", fmt.Errorf("failed to start build process: %w", err)
}
Expand Down Expand Up @@ -105,7 +110,7 @@ func Build(release bool, target string, features []string) (string, error) {
}
}
if err = cmd.Wait(); err != nil {
return "", fmt.Errorf("build process failed: %w", err)
return "", fmt.Errorf("build process failed: %w\nStandard error output:\n%s", err, stderr.String())
}

if executable == "" {
Expand Down

0 comments on commit 5e43015

Please sign in to comment.