commit 3ec3418

delthas  ·  2022-12-22 16:15:30 +0000 UTC
parent 37623d5
np: Bump libnp & be more verbose with errors
3 files changed,  +13, -10
M go.mod
M go.sum
+10, -7
 1@@ -360,7 +360,10 @@ func commandDoMe(app *App, args []string) (err error) {
 2 }
 3 
 4 func commandDoNP(app *App, args []string) (err error) {
 5-	song := getSong()
 6+	song, err := getSong()
 7+	if err != nil {
 8+		return fmt.Errorf("failed detecting the song: %v", err)
 9+	}
10 	if song == "" {
11 		return fmt.Errorf("no song was detected")
12 	}
13@@ -809,18 +812,18 @@ func (app *App) handleInput(buffer, content string) error {
14 	return cmd.Handle(app, args)
15 }
16 
17-func getSong() string {
18-	ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
19+func getSong() (string, error) {
20+	ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
21 	defer cancel()
22 	info, err := libnp.GetInfo(ctx)
23 	if err != nil {
24-		return ""
25+		return "", err
26 	}
27 	if info == nil {
28-		return ""
29+		return "", nil
30 	}
31 	if info.Title == "" {
32-		return ""
33+		return "", nil
34 	}
35 
36 	var sb strings.Builder
37@@ -837,5 +840,5 @@ func getSong() string {
38 			fmt.Fprintf(&sb, " — %s", info.URL)
39 		}
40 	}
41-	return sb.String()
42+	return sb.String(), nil
43 }
M go.mod
+1, -1
1@@ -4,7 +4,7 @@ go 1.16
2 
3 require (
4 	git.sr.ht/~emersion/go-scfg v0.0.0-20201019143924-142a8aa629fc
5-	github.com/delthas/go-libnp v0.0.0-20221221144027-c473a063cc72
6+	github.com/delthas/go-libnp v0.0.0-20221222161248-0e45ece1f878
7 	github.com/delthas/go-localeinfo v0.0.0-20221116001557-686a1e185118
8 	github.com/gdamore/tcell/v2 v2.5.4-0.20221017224006-ede1dd5ee680
9 	github.com/mattn/go-runewidth v0.0.14
M go.sum
+2, -2
 1@@ -2,8 +2,8 @@ git.sr.ht/~emersion/go-scfg v0.0.0-20201019143924-142a8aa629fc h1:51BD67xFX+bozd
 2 git.sr.ht/~emersion/go-scfg v0.0.0-20201019143924-142a8aa629fc/go.mod h1:t+Ww6SR24yYnXzEWiNlOY0AFo5E9B73X++10lrSpp4U=
 3 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 4 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 5-github.com/delthas/go-libnp v0.0.0-20221221144027-c473a063cc72 h1:CSoQd6Kw/fqPiXIEA9xnzdvyz0ZkplYUNGMBMQ7EGmw=
 6-github.com/delthas/go-libnp v0.0.0-20221221144027-c473a063cc72/go.mod h1:aGVXnhWpDlt5U4SphG97o1gszctZKvBTXy320E8Buw4=
 7+github.com/delthas/go-libnp v0.0.0-20221222161248-0e45ece1f878 h1:v8W8eW7eb2bHFXBA80UKcoe0TvEu46NlTHSDRvgAbMU=
 8+github.com/delthas/go-libnp v0.0.0-20221222161248-0e45ece1f878/go.mod h1:aGVXnhWpDlt5U4SphG97o1gszctZKvBTXy320E8Buw4=
 9 github.com/delthas/go-localeinfo v0.0.0-20221116001557-686a1e185118 h1:Xzf9ra1QRJXD62gwudjI2iBq7x9CusvHd83Dg2OnUmE=
10 github.com/delthas/go-localeinfo v0.0.0-20221116001557-686a1e185118/go.mod h1:sG54BxlyQgIskYURLrg7mvhoGBe0Qq12DNtYRALwNa4=
11 github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=