From c68c99e5280aeda977f31b55f46bcea1ccb4e672 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Wed, 30 Mar 2022 20:21:18 +0400 Subject: [PATCH] Return error for IcecastLastPlayedSongs. --- internal/radio/icecast.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/radio/icecast.go b/internal/radio/icecast.go index 566d893..c58fa85 100644 --- a/internal/radio/icecast.go +++ b/internal/radio/icecast.go @@ -63,15 +63,17 @@ func IcecastGetStatus(icecastURL string) (*IcecastStatus, error) { return iceStat, nil } -func IcecastLastPlayedSongs(lastNSongs int, playlistPath string) []Song { +func IcecastLastPlayedSongs(lastNSongs int, playlistPath string) ([]Song, error) { songs := make([]Song, 0) - cmd := fmt.Sprintf("tail -n%d %s | head -n-1 | cut -d\"|\" -f1,4", lastNSongs+1, playlistPath) - o := exec.Command("bash", "-c", cmd) - out, _ := o.CombinedOutput() + cmd := fmt.Sprintf("tail -n%d %s | head -n-1 | cut -d'|' -f1,4", lastNSongs+1, playlistPath) + out, err := exec.Command("bash", "-c", cmd).CombinedOutput() + if err != nil { + return songs, err + } if len(out) == 0 { - return songs + return songs, nil } songs_ := strings.Split(string(out), "\n") @@ -89,5 +91,5 @@ func IcecastLastPlayedSongs(lastNSongs int, playlistPath string) []Song { Title: at[1]}) } - return songs + return songs, nil }