func (g *gmBuilder) runCMD(in io.Reader, out io.Writer) error { g.args = append(g.args, "-", "-") cmd := exec.Command("gm", g.args...) stderr := bytes.NewBuffer(nil) cmd.Stdin = in cmd.Stdout = out cmd.Stderr = stderr cmd.Start() cmdDone := make(chan error, 1) go func() { cmdDone <- cmd.Wait() }() select { case <-time.After(time.Duration(500000) * time.Millisecond): err := g.killCmd(cmd) if err != nil { return err } <-cmdDone return errors2.NewInternal("Command timed out") case err := <-cmdDone: if err != nil { return errors2.NewInternal(stderr.String()) } } return nil }
func (g *gmBuilder) killCmd(cmd *exec.Cmd) error { if err := cmd.Process.Kill(); err != nil { return errors2.NewInternal(fmt.Sprintf("Failed to kill command: %v", err)) } return nil }
func Err(err error) error { if err == nil { return nil } if err.Error() == "not found" { return errors2.NewNotFound("not found") } return errors2.NewInternal(err.Error()) }
func Err(err error) error { if err == nil { return nil } switch err.Error() { case "sql: no rows in result set": return errors2.NewNotFound("not found") } return errors2.NewInternal(err.Error()) }