Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure user-specified error classes take priority #115

Merged
merged 2 commits into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions bugsnag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestNotify(t *testing.T) {
md := MetaData{"test": {"password": "sneaky", "value": "able", "broken": complex(1, 2), "recurse": recurse}}
user := User{Id: "123", Name: "Conrad", Email: "me@cirw.in"}
config := generateSampleConfig(ts.URL)
Notify(fmt.Errorf("hello world"), StartSession(context.Background()), config, user, Context{"testing"}, md)
Notify(fmt.Errorf("hello world"), StartSession(context.Background()), config, user, ErrorClass{Name: "ExpectedErrorClass"}, Context{"testing"}, md)

json, err := simplejson.NewJson(<-reports)

Expand All @@ -116,7 +116,7 @@ func TestNotify(t *testing.T) {
Unhandled: false,
Request: &RequestJSON{},
User: &User{Id: "123", Name: "Conrad", Email: "me@cirw.in"},
Exceptions: []exceptionJSON{{ErrorClass: "*errors.errorString", Message: "hello world"}},
Exceptions: []exceptionJSON{{ErrorClass: "ExpectedErrorClass", Message: "hello world"}},
})
assertValidSession(t, event, handled)

Expand Down
5 changes: 4 additions & 1 deletion event.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ func newEvent(rawData []interface{}, notifier *Notifier) (*Event, *Configuration
case error, errors.Error:
err = errors.New(datum.(error), 1)
event.Error = err
event.ErrorClass = err.TypeName()
// Only assign automatically if not explicitly set through ErrorClass already
if event.ErrorClass == "" {
event.ErrorClass = err.TypeName()
}
event.Message = err.Error()
event.Stacktrace = make([]stackFrame, len(err.StackFrames()))

Expand Down
6 changes: 5 additions & 1 deletion features/fixtures/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ func unhandledCrash() {

func handledError() {
if _, err := os.Open("nonexistent_file.txt"); err != nil {
bugsnag.Notify(err)
if errClass := os.Getenv("ERROR_CLASS"); errClass != "" {
bugsnag.Notify(err, bugsnag.ErrorClass{Name: errClass})
} else {
bugsnag.Notify(err)
}
}
// Give some time for the error to be sent before exiting
time.Sleep(200 * time.Millisecond)
Expand Down
6 changes: 6 additions & 0 deletions features/fixtures/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
- GO_VERSION
environment:
- API_KEY
- ERROR_CLASS
- BUGSNAG_ENDPOINT
- APP_VERSION
- APP_TYPE
Expand All @@ -30,6 +31,7 @@ services:
- "4512:4512"
environment:
- API_KEY
- ERROR_CLASS
- BUGSNAG_ENDPOINT
- APP_VERSION
- APP_TYPE
Expand All @@ -54,6 +56,7 @@ services:
- "4511:4511"
environment:
- API_KEY
- ERROR_CLASS
- BUGSNAG_ENDPOINT
- APP_VERSION
- APP_TYPE
Expand All @@ -77,6 +80,7 @@ services:
- "4513:4513"
environment:
- API_KEY
- ERROR_CLASS
- BUGSNAG_ENDPOINT
- APP_VERSION
- APP_TYPE
Expand All @@ -101,6 +105,7 @@ services:
- "4514:4514"
environment:
- API_KEY
- ERROR_CLASS
- BUGSNAG_ENDPOINT
- APP_VERSION
- APP_TYPE
Expand All @@ -126,6 +131,7 @@ services:
- "4515:4515"
environment:
- API_KEY
- ERROR_CLASS
- BUGSNAG_ENDPOINT
- APP_VERSION
- APP_TYPE
Expand Down
6 changes: 5 additions & 1 deletion features/fixtures/gin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ func unhandledCrash(c *gin.Context) {

func handledError(c *gin.Context) {
if _, err := os.Open("nonexistent_file.txt"); err != nil {
bugsnag.Notify(err, c.Request.Context())
if errClass := os.Getenv("ERROR_CLASS"); errClass != "" {
bugsnag.Notify(err, c.Request.Context(), bugsnag.ErrorClass{Name: errClass})
} else {
bugsnag.Notify(err, c.Request.Context())
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion features/fixtures/martini/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ func unhandledCrash() {

func handledError(r *http.Request) {
if _, err := os.Open("nonexistent_file.txt"); err != nil {
bugsnag.Notify(err, r.Context())
if errClass := os.Getenv("ERROR_CLASS"); errClass != "" {
bugsnag.Notify(err, r.Context(), bugsnag.ErrorClass{Name: errClass})
} else {
bugsnag.Notify(err, r.Context())
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion features/fixtures/negroni/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ func unhandledCrash(w http.ResponseWriter, r *http.Request) {

func handledError(w http.ResponseWriter, r *http.Request) {
if _, err := os.Open("nonexistent_file.txt"); err != nil {
bugsnag.Notify(err, r.Context())
if errClass := os.Getenv("ERROR_CLASS"); errClass != "" {
bugsnag.Notify(err, r.Context(), bugsnag.ErrorClass{Name: errClass})
} else {
bugsnag.Notify(err, r.Context())
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion features/fixtures/net_http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ func configureBasicBugsnag() {

func handledError(w http.ResponseWriter, r *http.Request) {
if _, err := os.Open("nonexistent_file.txt"); err != nil {
bugsnag.Notify(err, r.Context())
if errClass := os.Getenv("ERROR_CLASS"); errClass != "" {
bugsnag.Notify(err, r.Context(), bugsnag.ErrorClass{Name: errClass})
} else {
bugsnag.Notify(err, r.Context())
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion features/fixtures/revel/app/controllers/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ func (c App) Index() revel.Result {

func (c App) Handled() revel.Result {
if _, err := os.Open("nonexistent_file.txt"); err != nil {
bugsnag.Notify(err, c.Args["context"])
if errClass := os.Getenv("ERROR_CLASS"); errClass != "" {
bugsnag.Notify(err, c.Args["context"], bugsnag.ErrorClass{Name: errClass})
} else {
bugsnag.Notify(err, c.Args["context"])
}
}
return c.Render()
}
Expand Down
14 changes: 14 additions & 0 deletions features/gin_features/handled.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@ Scenario: A handled error sends a report
And the event "severityReason.type" equals "handledError" for request 0
And the exception "errorClass" equals "*os.PathError" for request 0
And the "file" of stack frame 0 equals "main.go" for request 0

Scenario: A handled error sends a report with a custom name
Given I set environment variable "ERROR_CLASS" to "MyCustomErrorClass"
When I start the service "gin"
And I wait for the app to open port "4511"
And I wait for 2 seconds
And I open the URL "http://localhost:4511/handled"
Then I wait to receive a request
And the request 0 is a valid error report with api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
And the event "unhandled" is false for request 0
And the event "severity" equals "warning" for request 0
And the event "severityReason.type" equals "handledError" for request 0
And the exception "errorClass" equals "MyCustomErrorClass" for request 0
And the "file" of stack frame 0 equals "main.go" for request 0
14 changes: 14 additions & 0 deletions features/martini_features/handled.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@ Scenario: A handled error sends a report
And the event "severityReason.type" equals "handledError" for request 0
And the exception "errorClass" equals "*os.PathError" for request 0
And the "file" of stack frame 0 equals "main.go" for request 0

Scenario: A handled error sends a report with a custom name
Given I set environment variable "ERROR_CLASS" to "MyCustomErrorClass"
When I start the service "martini"
And I wait for the app to open port "4513"
And I wait for 2 seconds
And I open the URL "http://localhost:4513/handled"
Then I wait to receive a request
And the request 0 is a valid error report with api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
And the event "unhandled" is false for request 0
And the event "severity" equals "warning" for request 0
And the event "severityReason.type" equals "handledError" for request 0
And the exception "errorClass" equals "MyCustomErrorClass" for request 0
And the "file" of stack frame 0 equals "main.go" for request 0
14 changes: 14 additions & 0 deletions features/negroni_features/handled.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@ Scenario: A handled error sends a report
And the event "severityReason.type" equals "handledError" for request 0
And the exception "errorClass" equals "*os.PathError" for request 0
And the "file" of stack frame 0 equals "main.go" for request 0

Scenario: A handled error sends a report with a custom name
Given I set environment variable "ERROR_CLASS" to "MyCustomErrorClass"
When I start the service "negroni"
And I wait for the app to open port "4514"
And I wait for 2 seconds
And I open the URL "http://localhost:4514/handled"
Then I wait to receive a request
And the request 0 is a valid error report with api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
And the event "unhandled" is false for request 0
And the event "severity" equals "warning" for request 0
And the event "severityReason.type" equals "handledError" for request 0
And the exception "errorClass" equals "MyCustomErrorClass" for request 0
And the "file" of stack frame 0 equals "main.go" for request 0
14 changes: 14 additions & 0 deletions features/net_http_features/handled.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@ Scenario: A handled error sends a report
And the event "severityReason.type" equals "handledError" for request 0
And the exception "errorClass" equals "*os.PathError" for request 0
And the "file" of stack frame 0 equals "main.go" for request 0

Scenario: A handled error sends a report with a custom name
Given I set environment variable "ERROR_CLASS" to "MyCustomErrorClass"
When I start the service "nethttp"
And I wait for the app to open port "4512"
And I wait for 2 seconds
And I open the URL "http://localhost:4512/handled"
Then I wait to receive a request
And the request 0 is a valid error report with api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
And the event "unhandled" is false for request 0
And the event "severity" equals "warning" for request 0
And the event "severityReason.type" equals "handledError" for request 0
And the exception "errorClass" equals "MyCustomErrorClass" for request 0
And the "file" of stack frame 0 equals "main.go" for request 0
11 changes: 11 additions & 0 deletions features/plain_features/handled.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ Scenario: A handled error sends a report
And the event "severityReason.type" equals "handledError"
And the exception "errorClass" equals "*os.PathError"
And the "file" of stack frame 0 equals "main.go"

Scenario: A handled error sends a report with a custom name
Given I set environment variable "ERROR_CLASS" to "MyCustomErrorClass"
When I run the go service "app" with the test case "handled"
Then I wait to receive a request
And the request is a valid error report with api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
And the event "unhandled" is false
And the event "severity" equals "warning"
And the event "severityReason.type" equals "handledError"
And the exception "errorClass" equals "MyCustomErrorClass"
And the "file" of stack frame 0 equals "main.go"
14 changes: 14 additions & 0 deletions features/revel_features/handled.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@ Scenario: A handled error sends a report
And the event "severityReason.type" equals "handledError" for request 0
And the exception "errorClass" equals "*os.PathError" for request 0
And the "file" of stack frame 0 equals "controllers/app.go" for request 0

Scenario: A handled error sends a report with a custom name
Given I set environment variable "ERROR_CLASS" to "MyCustomErrorClass"
When I start the service "revel"
And I wait for the app to open port "4515"
And I wait for 4 seconds
And I open the URL "http://localhost:4515/handled"
Then I wait to receive a request
And the request 0 is a valid error report with api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
And the event "unhandled" is false for request 0
And the event "severity" equals "warning" for request 0
And the event "severityReason.type" equals "handledError" for request 0
And the exception "errorClass" equals "MyCustomErrorClass" for request 0
And the "file" of stack frame 0 equals "controllers/app.go" for request 0