Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo: Dump stderr on compilation error #306

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading