Skip to content

Commit a83b45c

Browse files
authored
Merge pull request #3640 from ActiveState/mitchell/dx-3210
Add unique(ish) ID to error messages for easier Rollbar cross-referencing.
2 parents 971037d + 3e8a5cb commit a83b45c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

internal/runbits/errors/errors.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"strings"
88

9+
"github.com/google/uuid"
910
"github.com/thoas/go-funk"
1011

1112
"github.com/ActiveState/cli/internal/analytics"
@@ -32,6 +33,19 @@ type OutputError struct {
3233
error
3334
}
3435

36+
var errorId string
37+
38+
// Returns a relatively unique ID for error reporting.
39+
// We report this ID in non-user-facing errors and on Rollbar so we can cross-reference them.
40+
// Repeated calls return the same ID.
41+
func getErrorId() string {
42+
if errorId == "" {
43+
errorId = uuid.New().String()[:8]
44+
}
45+
46+
return errorId
47+
}
48+
3549
func (o *OutputError) MarshalOutput(f output.Format) interface{} {
3650
var outLines []string
3751
isInputError := locale.IsInputError(o.error)
@@ -68,7 +82,11 @@ func (o *OutputError) MarshalOutput(f output.Format) interface{} {
6882

6983
// Concatenate error tips
7084
errorTips := getErrorTips(o.error)
71-
errorTips = append(errorTips, locale.Tl("err_help_forum", "Ask For Help → [ACTIONABLE]{{.V0}}[/RESET]", constants.ForumsURL))
85+
helpMsg := locale.Tl("err_help_forum", "Ask For Help → [ACTIONABLE]{{.V0}}[/RESET]", constants.ForumsURL)
86+
if IsReportableError(o.error) {
87+
helpMsg += "\n " + locale.Tl("err_help_error_id", "When doing so, please reference the following error ID: {{.V0}}", getErrorId())
88+
}
89+
errorTips = append(errorTips, helpMsg)
7290

7391
// Print tips
7492
enableTips := os.Getenv(constants.DisableErrorTipsEnvVarName) != "true" && f == output.PlainFormatName
@@ -197,7 +215,7 @@ func ReportError(err error, cmd *captain.Command, an analytics.Dispatcher) {
197215
var action string
198216
errorMsg := err.Error()
199217
if IsReportableError(err) {
200-
multilog.Critical("Returning error:\n%s\nCreated at:\n%s", errs.JoinMessage(err), stack)
218+
multilog.Critical("Returning error (ID: %s):\n%s\nCreated at:\n%s", getErrorId(), errs.JoinMessage(err), stack)
201219
action = anaConst.ActCommandError
202220
} else {
203221
logging.Debug("Returning input error:\n%s\nCreated at:\n%s", errs.JoinMessage(err), stack)

0 commit comments

Comments
 (0)