1
0

Check if path is valid. Simplified error handling.

This commit is contained in:
Alexander Andreev 2022-08-29 22:20:05 +04:00
parent b26f23b4e3
commit 7dd517ea8f
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -1,7 +1,6 @@
package liquidsoap package liquidsoap
import ( import (
"fmt"
"os" "os"
"os/exec" "os/exec"
"syscall" "syscall"
@ -17,6 +16,10 @@ type Liquidsoap struct {
} }
func NewLiquidsoap(liquidsoapPath, scriptPath string) (*Liquidsoap, error) { func NewLiquidsoap(liquidsoapPath, scriptPath string) (*Liquidsoap, error) {
if _, err := exec.LookPath(liquidsoapPath); err != nil {
return nil, err
}
cmd := exec.Command(liquidsoapPath, scriptPath) cmd := exec.Command(liquidsoapPath, scriptPath)
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
@ -28,14 +31,10 @@ func NewLiquidsoap(liquidsoapPath, scriptPath string) (*Liquidsoap, error) {
time.Sleep(4 * time.Second) time.Sleep(4 * time.Second)
if _, err := os.FindProcess(cmd.Process.Pid); err != nil { 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 { 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{ return &Liquidsoap{