-
Notifications
You must be signed in to change notification settings - Fork 14
Add unique(ish) ID to error messages for easier Rollbar cross-referencing. #3640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ import ( | |||
| "os" | ||||
| "strings" | ||||
|
|
||||
| "github.com/google/uuid" | ||||
| "github.com/thoas/go-funk" | ||||
|
|
||||
| "github.com/ActiveState/cli/internal/analytics" | ||||
|
|
@@ -32,6 +33,19 @@ type OutputError struct { | |||
| error | ||||
| } | ||||
|
|
||||
| var errorId string | ||||
|
|
||||
| // Returns a relatively unique ID for error reporting. | ||||
| // We report this ID in non-user-facing errors and on Rollbar so we can cross-reference them. | ||||
| // Repeated calls return the same ID. | ||||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine because there can only ever be one error we report to the user that we'd have to lookup on Rollbar. |
||||
| func getErrorId() string { | ||||
| if errorId == "" { | ||||
| errorId = uuid.New().String()[:8] | ||||
| } | ||||
|
|
||||
| return errorId | ||||
| } | ||||
|
|
||||
| func (o *OutputError) MarshalOutput(f output.Format) interface{} { | ||||
| var outLines []string | ||||
| isInputError := locale.IsInputError(o.error) | ||||
|
|
@@ -68,7 +82,11 @@ func (o *OutputError) MarshalOutput(f output.Format) interface{} { | |||
|
|
||||
| // Concatenate error tips | ||||
| errorTips := getErrorTips(o.error) | ||||
| errorTips = append(errorTips, locale.Tl("err_help_forum", "Ask For Help → [ACTIONABLE]{{.V0}}[/RESET]", constants.ForumsURL)) | ||||
| helpMsg := locale.Tl("err_help_forum", "Ask For Help → [ACTIONABLE]{{.V0}}[/RESET]", constants.ForumsURL) | ||||
| if IsReportableError(o.error) { | ||||
| helpMsg += "\n " + locale.Tl("err_help_error_id", "When doing so, please reference the following error ID: {{.V0}}", getErrorId()) | ||||
| } | ||||
| errorTips = append(errorTips, helpMsg) | ||||
|
|
||||
| // Print tips | ||||
| enableTips := os.Getenv(constants.DisableErrorTipsEnvVarName) != "true" && f == output.PlainFormatName | ||||
|
|
@@ -197,7 +215,7 @@ func ReportError(err error, cmd *captain.Command, an analytics.Dispatcher) { | |||
| var action string | ||||
| errorMsg := err.Error() | ||||
| if IsReportableError(err) { | ||||
| multilog.Critical("Returning error:\n%s\nCreated at:\n%s", errs.JoinMessage(err), stack) | ||||
| multilog.Critical("Returning error (ID: %s):\n%s\nCreated at:\n%s", getErrorId(), errs.JoinMessage(err), stack) | ||||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will call cli/internal/multilog/multilog.go Line 25 in bb4d163
|
||||
| action = anaConst.ActCommandError | ||||
| } else { | ||||
| logging.Debug("Returning input error:\n%s\nCreated at:\n%s", errs.JoinMessage(err), stack) | ||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need a totally unique ID, just something to search for in Rollbar to find the user's log.