From 71077f8274aed543123d4d55956013029676a592 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Fri, 17 May 2024 14:51:24 +0200 Subject: [PATCH] fix(cli/rm/rm.go): using panic is not user friendly (#1608) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I manually tested the cli and concluded that it's too easy to reach the panic caused by runtimex.Try0 over there and it would expose panics to users too frequently. Let's just convert those into normal error checks. Here is what we would previously get: ``` % ./ooniprobe rm ? Are you sure you wish to delete the result #0 [Use arrows to move, type to filter] true > false panic: Try0: interrupt [...] ``` So, here I just pressed ^D and got a panic. Ouch! After the diff, we have this: ``` % ./ooniprobe rm ? Are you sure you wish to delete the result #0 false ⨯ failure in main command error=canceled by user ``` and: ``` % ./ooniprobe rm --all ? Are you sure you wish to delete ALL results false ⨯ failure in main command error=canceled by user ``` It seems much better, isn't it? Part of the QA for https://github.com/ooni/probe/issues/2722 --- cmd/ooniprobe/internal/cli/rm/rm.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/ooniprobe/internal/cli/rm/rm.go b/cmd/ooniprobe/internal/cli/rm/rm.go index ab3409a02..79edbbce3 100644 --- a/cmd/ooniprobe/internal/cli/rm/rm.go +++ b/cmd/ooniprobe/internal/cli/rm/rm.go @@ -9,7 +9,6 @@ import ( "github.com/apex/log" "github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/cli/root" "github.com/ooni/probe-cli/v3/internal/database" - "github.com/ooni/probe-cli/v3/internal/runtimex" "github.com/upper/db/v4" ) @@ -21,7 +20,7 @@ func deleteAll(d *database.Database, skipInteractive bool) error { Options: []string{"true", "false"}, Default: "false", } - runtimex.Try0(survey.AskOne(confirm, &answer, nil)) + _ = survey.AskOne(confirm, &answer, nil) // no error checking: we rely on the default value if answer == "false" { return errors.New("canceled by user") } @@ -81,7 +80,7 @@ func init() { Options: []string{"true", "false"}, Default: "false", } - runtimex.Try0(survey.AskOne(confirm, &answer, nil)) + _ = survey.AskOne(confirm, &answer, nil) // no error checking: we rely on the default value if answer == "false" { return errors.New("canceled by user") }