fix: error could cause infinite hang
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
6c8b9d191c
commit
c0e975e139
@ -1,9 +1,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"github.com/sirupsen/logrus"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,8 +19,8 @@ var rootCmd = &cobra.Command{
|
|||||||
func Execute() {
|
func Execute() {
|
||||||
err := rootCmd.Execute()
|
err := rootCmd.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
logrus.Error(err)
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,6 +258,14 @@ func (p *Project) Reload(path string, stop <-chan bool) {
|
|||||||
p.stamp("error", out, msg, "")
|
p.stamp("error", out, msg, "")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
} else {
|
||||||
|
if install.Err != nil {
|
||||||
|
log.Println(p.parent.Prefix("Install failed for: " + p.Name + " exiting"))
|
||||||
|
}
|
||||||
|
if build.Err != nil {
|
||||||
|
log.Println(p.parent.Prefix("Build failed for: " + p.Name + " exiting"))
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
if done {
|
if done {
|
||||||
return
|
return
|
||||||
@ -667,7 +675,7 @@ func (r *Response) print(start time.Time, p *Project) {
|
|||||||
if r.Err != nil {
|
if r.Err != nil {
|
||||||
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Bold(r.Name), "\n", r.Err.Error())
|
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Bold(r.Name), "\n", r.Err.Error())
|
||||||
out = BufferOut{Time: time.Now(), Text: r.Err.Error(), Type: r.Name, Stream: r.Out}
|
out = BufferOut{Time: time.Now(), Text: r.Err.Error(), Type: r.Name, Stream: r.Out}
|
||||||
p.stamp("error", out, msg, r.Out)
|
p.stamp("errororororororororor", out, msg, r.Out)
|
||||||
} else {
|
} else {
|
||||||
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", Green.Bold(r.Name), "completed in", Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
|
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", Green.Bold(r.Name), "completed in", Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
|
||||||
out = BufferOut{Time: time.Now(), Text: r.Name + " in " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"}
|
out = BufferOut{Time: time.Now(), Text: r.Name + " in " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"}
|
||||||
|
@ -4,8 +4,8 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -86,7 +86,6 @@ func (t *Tools) Setup() {
|
|||||||
// go install
|
// go install
|
||||||
t.Install.name = "Install"
|
t.Install.name = "Install"
|
||||||
t.Install.cmd = replace([]string{gocmd, "install"}, t.Install.Method)
|
t.Install.cmd = replace([]string{gocmd, "install"}, t.Install.Method)
|
||||||
fmt.Println(t.Install.cmd)
|
|
||||||
t.Install.Args = split([]string{}, t.Install.Args)
|
t.Install.Args = split([]string{}, t.Install.Args)
|
||||||
// go build
|
// go build
|
||||||
if t.Build.Status {
|
if t.Build.Status {
|
||||||
@ -104,7 +103,7 @@ func (t *Tool) Exec(path string, stop <-chan bool) (response Response) {
|
|||||||
}
|
}
|
||||||
// check if there is at least one go file
|
// check if there is at least one go file
|
||||||
matched := false
|
matched := false
|
||||||
files, _ := ioutil.ReadDir(path)
|
files, _ := os.ReadDir(path)
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
matched, _ = filepath.Match("*.go", f.Name())
|
matched, _ = filepath.Match("*.go", f.Name())
|
||||||
if matched {
|
if matched {
|
||||||
@ -180,14 +179,27 @@ func (t *Tool) Compile(path string, stop <-chan bool) (response Response) {
|
|||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
cmd.Stderr = &stderr
|
cmd.Stderr = &stderr
|
||||||
// Start command
|
// Start command
|
||||||
cmd.Start()
|
err := cmd.Start()
|
||||||
go func() { done <- cmd.Wait() }()
|
if err != nil {
|
||||||
|
err := cmd.Process.Kill()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
done <- cmd.Wait()
|
||||||
|
}()
|
||||||
// Wait a result
|
// Wait a result
|
||||||
response.Name = t.name
|
response.Name = t.name
|
||||||
select {
|
select {
|
||||||
case <-stop:
|
case <-stop:
|
||||||
// Stop running command
|
// Stop running command
|
||||||
cmd.Process.Kill()
|
err := cmd.Process.Kill()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
case err := <-done:
|
case err := <-done:
|
||||||
// Command completed
|
// Command completed
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user