From 7dd517ea8f61758d528b307865b197c1d18961bb Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Mon, 29 Aug 2022 22:20:05 +0400 Subject: [PATCH] Check if path is valid. Simplified error handling. --- internal/radio/liquidsoap/liquidsoap.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/radio/liquidsoap/liquidsoap.go b/internal/radio/liquidsoap/liquidsoap.go index 182742d..76c7a3a 100644 --- a/internal/radio/liquidsoap/liquidsoap.go +++ b/internal/radio/liquidsoap/liquidsoap.go @@ -1,7 +1,6 @@ package liquidsoap import ( - "fmt" "os" "os/exec" "syscall" @@ -17,6 +16,10 @@ type Liquidsoap struct { } func NewLiquidsoap(liquidsoapPath, scriptPath string) (*Liquidsoap, error) { + if _, err := exec.LookPath(liquidsoapPath); err != nil { + return nil, err + } + cmd := exec.Command(liquidsoapPath, scriptPath) if err := cmd.Start(); err != nil { @@ -28,14 +31,10 @@ func NewLiquidsoap(liquidsoapPath, scriptPath string) (*Liquidsoap, error) { time.Sleep(4 * time.Second) if _, err := os.FindProcess(cmd.Process.Pid); err != nil { - stderr, _ := cmd.StderrPipe() - var stderr_content string - fmt.Fscanln(stderr, &stderr_content) - if err_wait := cmd.Wait(); err != nil { - return nil, errors.Wrapf(err_wait, "%s: %s", err.Error(), stderr_content) + return nil, errors.Wrap(err, err_wait.Error()) } - return nil, errors.Wrapf(err, "%s: %s", err.Error(), stderr_content) + return nil, err } return &Liquidsoap{