-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
catch.go
33 lines (29 loc) · 1.02 KB
/
catch.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
// Copyright 2019 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 (
"runtime"
"github.com/cockroachdb/errors"
)
// ShouldCatch is used for catching errors thrown as panics. Its argument is the
// object returned by recover(); it succeeds if the object is an error. If the
// error is a runtime.Error, it is converted to an internal error (see
// errors.AssertionFailedf).
func ShouldCatch(obj interface{}) (ok bool, err error) {
err, ok = obj.(error)
if ok {
if _, isRuntime := err.(runtime.Error); isRuntime {
// Convert runtime errors to internal errors, which display the stack and
// get reported to Sentry.
err = errors.NewAssertionErrorWithWrappedErrf(err, "")
}
}
return ok, err
}