From bb2bfdc9180809cd2eaa1d9682a2df354fdde660 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Thu, 8 Oct 2020 19:46:11 +0100 Subject: [PATCH] Show a better err msg when Control-C is hit (#3446) Currently the error message is "context canceled" which is cryptic --- cmd/error.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/error.go b/cmd/error.go index a3cb8912..93fb7e29 100644 --- a/cmd/error.go +++ b/cmd/error.go @@ -17,6 +17,8 @@ package cmd import ( + "context" + "errors" "fmt" "strings" "unicode" @@ -81,7 +83,13 @@ func fatal(err *probe.Error, msg string, data ...interface{}) { msg = fmt.Sprintf(msg, data...) errmsg := err.String() if !globalDebug { - errmsg = err.ToGoError().Error() + e := err.ToGoError() + if errors.Is(e, context.Canceled) { + // This will replace context canceled error message + // that the user is seeing to a better one. + e = errors.New("Canceling upon user request") + } + errmsg = e.Error() } // Remove unnecessary leading spaces in generic/detailed error messages