github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/util/errorutil/error.go (about) 1 // Copyright 2017 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package errorutil 12 13 import ( 14 "context" 15 "fmt" 16 17 "github.com/cockroachdb/cockroach/pkg/settings" 18 "github.com/cockroachdb/cockroach/pkg/util/log" 19 "github.com/cockroachdb/errors" 20 ) 21 22 // UnexpectedWithIssueErrorf indicates an error with an associated Github issue. 23 // It's supposed to be used for conditions that would otherwise be checked by 24 // assertions, except that they fail and we need the public's help for tracking 25 // it down. 26 // The error message will invite users to report repros. 27 func UnexpectedWithIssueErrorf(issue int, format string, args ...interface{}) error { 28 err := errors.Newf(format, args...) 29 err = errors.Wrap(err, "unexpected error") 30 err = errors.WithSafeDetails(err, "issue #%d", errors.Safe(issue)) 31 err = errors.WithHint(err, 32 fmt.Sprintf("We've been trying to track this particular issue down. "+ 33 "Please report your reproduction at "+ 34 "https://github.com/cockroachdb/cockroach/issues/%d "+ 35 "unless that issue seems to have been resolved "+ 36 "(in which case you might want to update crdb to a newer version).", 37 issue)) 38 return err 39 } 40 41 // SendReport creates a Sentry report about the error, if the settings allow. 42 // The format string will be reproduced ad litteram in the report; the arguments 43 // will be sanitized. 44 func SendReport(ctx context.Context, sv *settings.Values, err error) { 45 if !log.ShouldSendReport(sv) { 46 return 47 } 48 event, extraDetails := errors.BuildSentryReport(err) 49 log.SendReport(ctx, log.ReportTypeError, event, extraDetails) 50 }