6
6
"os"
7
7
"strings"
8
8
9
+ "github.com/google/uuid"
9
10
"github.com/thoas/go-funk"
10
11
11
12
"github.com/ActiveState/cli/internal/analytics"
@@ -32,6 +33,19 @@ type OutputError struct {
32
33
error
33
34
}
34
35
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
+
35
49
func (o * OutputError ) MarshalOutput (f output.Format ) interface {} {
36
50
var outLines []string
37
51
isInputError := locale .IsInputError (o .error )
@@ -68,7 +82,11 @@ func (o *OutputError) MarshalOutput(f output.Format) interface{} {
68
82
69
83
// Concatenate error tips
70
84
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 )
72
90
73
91
// Print tips
74
92
enableTips := os .Getenv (constants .DisableErrorTipsEnvVarName ) != "true" && f == output .PlainFormatName
@@ -197,7 +215,7 @@ func ReportError(err error, cmd *captain.Command, an analytics.Dispatcher) {
197
215
var action string
198
216
errorMsg := err .Error ()
199
217
if IsReportableError (err ) {
200
- multilog .Critical ("Returning error: \n %s\n Created at:\n %s" , errs .JoinMessage (err ), stack )
218
+ multilog .Critical ("Returning error (ID: %s): \n %s\n Created at:\n %s" , getErrorId () , errs .JoinMessage (err ), stack )
201
219
action = anaConst .ActCommandError
202
220
} else {
203
221
logging .Debug ("Returning input error:\n %s\n Created at:\n %s" , errs .JoinMessage (err ), stack )
0 commit comments