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
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{