Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions internal/runbits/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"strings"

"github.com/google/uuid"
"github.com/thoas/go-funk"

"github.com/ActiveState/cli/internal/analytics"
Expand All @@ -32,6 +33,19 @@ type OutputError struct {
error
}

var errorId string

// Returns a relatively unique ID for error reporting.
Copy link
Collaborator Author

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.

// We report this ID in non-user-facing errors and on Rollbar so we can cross-reference them.
// Repeated calls return the same ID.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Copy link
Collaborator Author

@mitchell-as mitchell-as Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will call rollbar.Critical, which forwards our message and error ID to rollbar:

rollbar.Critical(format, args...)

action = anaConst.ActCommandError
} else {
logging.Debug("Returning input error:\n%s\nCreated at:\n%s", errs.JoinMessage(err), stack)
Expand Down
Loading