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