Skip to content
Snippets Groups Projects
Commit 659de86e0598 authored by steeve.chailloux's avatar steeve.chailloux
Browse files

pretty print error messages

parent dcf933cad0a6
No related branches found
No related tags found
No related merge requests found
Pipeline #36104 passed
package runner
import (
"fmt"
"github.com/go-cmd/cmd"
)
func RunCMD(c *cmd.Cmd) (err error, stdout, stderr []string) {
statusChan := c.Start()
status := <-statusChan
......@@ -4,11 +6,11 @@
"github.com/go-cmd/cmd"
)
func RunCMD(c *cmd.Cmd) (err error, stdout, stderr []string) {
statusChan := c.Start()
status := <-statusChan
if status.Error != nil {
return err, status.Stdout, status.Stderr
if status.Error != nil || status.Exit > 0 {
return fmt.Errorf("Cannot execute command: %w", err), status.Stdout, status.Stderr
}
stdout = status.Stdout
stderr = status.Stderr
......
......@@ -67,6 +67,9 @@
Str("stderr", strings.Join(stdErr, "\n")).
Msg("failed to run command")
// TODO: print error to stderr
// Error must be pretty printed to end users /!\
fmt.Printf("\n%s\n\n", strings.Join(stdErr, "\n"))
return fmt.Errorf("failed to run command: %w", err)
}
if tmpFile, err := ioutil.TempFile(tmpDir, fmt.Sprintf("compiled-%s-", name)); err != nil {
......@@ -101,6 +104,9 @@
Str("stderr", strings.Join(stdErr, "\n")).
Msg("failed to run command")
// TODO: print error to stderr
// Error message must be pretty printed to end users
fmt.Printf("\n%s\n\n", strings.Join(stdErr, "\n"))
return fmt.Errorf("failed to run command: %w", err)
}
if tmpFile, err := ioutil.TempFile(tmpDir, "fully-compiled-"); err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment