summaryrefslogtreecommitdiff
path: root/commands.go
diff options
context:
space:
mode:
authordelthas <delthas@dille.cc>2022-12-22 17:15:30 +0100
committerdelthas <delthas@dille.cc>2022-12-22 17:15:52 +0100
commit3ec341833671fcc89cab062cdb714fc81cf8b441 (patch)
treec8eb8bf2a4c5196489151ee2771ef8206a3c411e /commands.go
parentFix failing on addresses with a literal IP address without URLs (diff)
np: Bump libnp & be more verbose with errors
Diffstat (limited to 'commands.go')
-rw-r--r--commands.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/commands.go b/commands.go
index 6fb501f..2371878 100644
--- a/commands.go
+++ b/commands.go
@@ -360,7 +360,10 @@ func commandDoMe(app *App, args []string) (err error) {
}
func commandDoNP(app *App, args []string) (err error) {
- song := getSong()
+ song, err := getSong()
+ if err != nil {
+ return fmt.Errorf("failed detecting the song: %v", err)
+ }
if song == "" {
return fmt.Errorf("no song was detected")
}
@@ -809,18 +812,18 @@ func (app *App) handleInput(buffer, content string) error {
return cmd.Handle(app, args)
}
-func getSong() string {
- ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
+func getSong() (string, error) {
+ ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
defer cancel()
info, err := libnp.GetInfo(ctx)
if err != nil {
- return ""
+ return "", err
}
if info == nil {
- return ""
+ return "", nil
}
if info.Title == "" {
- return ""
+ return "", nil
}
var sb strings.Builder
@@ -837,5 +840,5 @@ func getSong() string {
fmt.Fprintf(&sb, " — %s", info.URL)
}
}
- return sb.String()
+ return sb.String(), nil
}