Debian Codegraph @

exception.go

raw
1 package raven
2
3 import (
4 "reflect"
5 "regexp"
6 )
7
8 var errorMsgPattern = regexp.MustCompile(`\A(\w+): (.+)\z`)
9
10 func NewException(err error, stacktrace *Stacktrace) *Exception {
11 msg := err.Error()
12 ex := &Exception{
13 Stacktrace: stacktrace,
14 Value: msg,
15 Type: reflect.TypeOf(err).String(),
16 }
17 if m := errorMsgPattern.FindStringSubmatch(msg); m != nil {
18 ex.Module, ex.Value = m[1], m[2]
19 }
20 return ex
21 }
22
23 // https://docs.getsentry.com/hosted/clientdev/interfaces/#failure-interfaces
24 type Exception struct {
25 // Required
26 Value string `json:"value"`
27
28 // Optional
29 Type string `json:"type,omitempty"`
30 Module string `json:"module,omitempty"`
31 Stacktrace *Stacktrace `json:"stacktrace,omitempty"`
32 }
33
34 func (e *Exception) Class() string { return "exception" }
35
36 func (e *Exception) Culprit() string {
37 if e.Stacktrace == nil {
38 return ""
39 }
40 return e.Stacktrace.Culprit()
41 }
42
43 // Exceptions allows for chained errors
44 // https://docs.sentry.io/clientdev/interfaces/exception/
45 type Exceptions struct {
46 // Required
47 Values []*Exception `json:"values"`
48 }
49
50 func (es Exceptions) Class() string { return "exception" }