Skip to content

Commit

Permalink
Surface any cargo metadata errors (#286)
Browse files Browse the repository at this point in the history
* Surface any cargo metadata errors

Related to #137 and #269.

* Fix logic

We were showing the verbose output when verbose was NOT set.
  • Loading branch information
fgsch committed May 27, 2021
1 parent 78f1b14 commit becf1a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/common/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s StreamingExec) Exec() error {
cmd.Stderr = io.MultiWriter(s.output, &stderrBuf)

if err := cmd.Run(); err != nil {
if !s.verbose && stderrBuf.Len() > 0 {
if s.verbose && stderrBuf.Len() > 0 {
return fmt.Errorf("error during execution process:\n%s", strings.TrimSpace(stderrBuf.String()))
}
return fmt.Errorf("error during execution process")
Expand Down
14 changes: 6 additions & 8 deletions pkg/compute/rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,15 @@ type CargoMetadata struct {
// Read the contents of the Cargo.lock file from filename.
func (m *CargoMetadata) Read() error {
cmd := exec.Command("cargo", "metadata", "--quiet", "--format-version", "1")
stdout, err := cmd.StdoutPipe()
stdoutStderr, err := cmd.CombinedOutput()
if err != nil {
if len(stdoutStderr) > 0 {
return fmt.Errorf("%s", strings.TrimSpace(string(stdoutStderr)))
}
return err
}
if err := cmd.Start(); err != nil {
return err
}
if err := json.NewDecoder(stdout).Decode(&m); err != nil {
return err
}
if err := cmd.Wait(); err != nil {
r := bytes.NewReader(stdoutStderr)
if err := json.NewDecoder(r).Decode(&m); err != nil {
return err
}
return nil
Expand Down

0 comments on commit becf1a0

Please sign in to comment.