From 615ab121dd3afe2a5da2dc9ca48fbfb325904166 Mon Sep 17 00:00:00 2001 From: Nick Paisley <2ep303@gmail.com> Date: Wed, 31 Jan 2024 11:26:58 -0600 Subject: [PATCH 1/6] build: Added latest go versions to test matrix "build: added latest go versions to test matrix" --- .github/workflows/test-package.yml | 2 +- features/fixtures/app/Dockerfile | 14 +++++++++++--- features/fixtures/app/main.go | 2 +- features/fixtures/autoconfigure/Dockerfile | 15 +++++++++++---- features/fixtures/net_http/Dockerfile | 15 +++++++++++---- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test-package.yml b/.github/workflows/test-package.yml index ff637390..0feee70e 100644 --- a/.github/workflows/test-package.yml +++ b/.github/workflows/test-package.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: os: [ubuntu, windows] - go-version: ['1.11', '1.12', '1.13', '1.14', '1.15', '1.16'] + go-version: ['1.11', '1.12', '1.13', '1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.20', '1.21', '1.22'] steps: - uses: actions/checkout@v2 diff --git a/features/fixtures/app/Dockerfile b/features/fixtures/app/Dockerfile index be61d206..2533d28d 100644 --- a/features/fixtures/app/Dockerfile +++ b/features/fixtures/app/Dockerfile @@ -8,14 +8,22 @@ ENV GOPATH /app COPY testbuild /app/src/github.com/bugsnag/bugsnag-go WORKDIR /app/src/github.com/bugsnag/bugsnag-go/v2 -RUN go get ./... +# Ensure subsequent steps are re-run if the GO_VERSION variable changes +ARG GO_VERSION + +# Get bugsnag dependencies using a conditional call to run go get or go install based on the go version +RUN if [[ $(echo -e "1.11\n$GO_VERSION\n1.16" | sort -V | head -2 | tail -1) == "$GO_VERSION" ]]; then \ + echo "Version is between 1.11 and 1.16, running go get"; \ + go get ./...; \ + else \ + echo "Version is greater than 1.16, running go install"; \ + go install ./...; \ + fi # Copy test scenarios COPY ./app /app/src/test WORKDIR /app/src/test -# Ensure subsequent steps are re-run if the GO_VERSION variable changes -ARG GO_VERSION # Create app module - avoid locking bugsnag dep by not checking it in # Skip on old versions of Go which pre-date modules RUN if [[ $GO_VERSION != '1.11' && $GO_VERSION != '1.12' ]]; then \ diff --git a/features/fixtures/app/main.go b/features/fixtures/app/main.go index 5617999f..0831ead2 100644 --- a/features/fixtures/app/main.go +++ b/features/fixtures/app/main.go @@ -130,7 +130,7 @@ func multipleUnhandled() { defer notifier.AutoNotify(ctx) panic("oops") } - +//go:noinline func unhandledCrash() { // Invalid type assertion, will panic func(a interface{}) string { diff --git a/features/fixtures/autoconfigure/Dockerfile b/features/fixtures/autoconfigure/Dockerfile index e0764b9f..b1ecac15 100644 --- a/features/fixtures/autoconfigure/Dockerfile +++ b/features/fixtures/autoconfigure/Dockerfile @@ -8,15 +8,22 @@ ENV GOPATH /app COPY testbuild /app/src/github.com/bugsnag/bugsnag-go WORKDIR /app/src/github.com/bugsnag/bugsnag-go/v2 -# Get bugsnag dependencies -RUN go get ./... +# Ensure subsequent steps are re-run if the GO_VERSION variable changes +ARG GO_VERSION + +# Get bugsnag dependencies using a conditional call to run go get or go install based on the go version +RUN if [[ $(echo -e "1.11\n$GO_VERSION\n1.16" | sort -V | head -2 | tail -1) == "$GO_VERSION" ]]; then \ + echo "Version is between 1.11 and 1.16, running go get"; \ + go get ./...; \ + else \ + echo "Version is greater than 1.16, running go install"; \ + go install ./...; \ + fi # Copy test scenarios COPY ./autoconfigure /app/src/test WORKDIR /app/src/test -# Ensure subsequent steps are re-run if the GO_VERSION variable changes -ARG GO_VERSION # Create app module - avoid locking bugsnag dep by not checking it in # Skip on old versions of Go which pre-date modules RUN if [[ $GO_VERSION != '1.11' && $GO_VERSION != '1.12' ]]; then \ diff --git a/features/fixtures/net_http/Dockerfile b/features/fixtures/net_http/Dockerfile index de86a56b..d8307933 100644 --- a/features/fixtures/net_http/Dockerfile +++ b/features/fixtures/net_http/Dockerfile @@ -10,15 +10,22 @@ ENV GOPATH /app COPY testbuild /app/src/github.com/bugsnag/bugsnag-go WORKDIR /app/src/github.com/bugsnag/bugsnag-go/v2 -# Get bugsnag dependencies -RUN go get ./... +# Ensure subsequent steps are re-run if the GO_VERSION variable changes +ARG GO_VERSION + +# Get bugsnag dependencies using a conditional call to run go get or go install based on the go version +RUN if [[ $(echo -e "1.11\n$GO_VERSION\n1.16" | sort -V | head -2 | tail -1) == "$GO_VERSION" ]]; then \ + echo "Version is between 1.11 and 1.16, running go get"; \ + go get ./...; \ + else \ + echo "Version is greater than 1.16, running go install"; \ + go install ./...; \ + fi # Copy test scenarios COPY ./net_http /app/src/test WORKDIR /app/src/test -# Ensure subsequent steps are re-run if the GO_VERSION variable changes -ARG GO_VERSION # Create app module - avoid locking bugsnag dep by not checking it in # Skip on old versions of Go which pre-date modules RUN if [[ $GO_VERSION != '1.11' && $GO_VERSION != '1.12' ]]; then \ From aa09604e93194a1ca98baeaca766613e845c28ca Mon Sep 17 00:00:00 2001 From: Tom Longridge Date: Tue, 6 Feb 2024 17:11:17 +0000 Subject: [PATCH 2/6] build: bump rack in MazeRunner deps --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 83b38f76..5ff8a517 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,7 +40,7 @@ GEM multi_test (0.1.2) os (1.0.1) power_assert (2.0.0) - rack (2.0.9) + rack (2.0.9.3) rake (12.3.3) test-unit (3.2.9) power_assert From ab426e24093320ed664ea19ffc5e82dd4036ab2c Mon Sep 17 00:00:00 2001 From: Bohdan Trotsenko Date: Sun, 18 Feb 2024 11:35:46 +0200 Subject: [PATCH 3/6] fix middleware panic on nil *http.Request --- middleware.go | 2 +- v2/middleware.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/middleware.go b/middleware.go index 3eac8645..b5018b85 100644 --- a/middleware.go +++ b/middleware.go @@ -62,7 +62,7 @@ func catchMiddlewarePanic(event *Event, config *Configuration, next func() error // use this as a template for writing your own Middleware. func httpRequestMiddleware(event *Event, config *Configuration) error { for _, datum := range event.RawData { - if request, ok := datum.(*http.Request); ok { + if request, ok := datum.(*http.Request); ok && request != nil { event.MetaData.Update(MetaData{ "request": { "params": request.URL.Query(), diff --git a/v2/middleware.go b/v2/middleware.go index 2ed721a0..2dc0ac9c 100644 --- a/v2/middleware.go +++ b/v2/middleware.go @@ -57,7 +57,7 @@ func (stack *middlewareStack) runBeforeFilter(f beforeFunc, event *Event, config // use this as a template for writing your own Middleware. func httpRequestMiddleware(event *Event, config *Configuration) error { for _, datum := range event.RawData { - if request, ok := datum.(*http.Request); ok { + if request, ok := datum.(*http.Request); ok && request != nil { event.MetaData.Update(MetaData{ "request": { "params": request.URL.Query(), From 379b2b7f4121316d1dce2d8b38f34af9dbe4e3bd Mon Sep 17 00:00:00 2001 From: Daria Bialobrzeska Date: Mon, 19 Feb 2024 18:14:22 +0100 Subject: [PATCH 4/6] Add testcase for nil http.Request in middleware callback --- v2/middleware_test.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/v2/middleware_test.go b/v2/middleware_test.go index e7a3ad30..ccd943d3 100644 --- a/v2/middleware_test.go +++ b/v2/middleware_test.go @@ -3,10 +3,12 @@ package bugsnag import ( "bytes" "fmt" - "github.com/bugsnag/bugsnag-go/v2/errors" "log" + "net/http" "reflect" "testing" + + "github.com/bugsnag/bugsnag-go/v2/errors" ) func TestMiddlewareOrder(t *testing.T) { @@ -95,3 +97,15 @@ func TestBeforeNotifyPanic(t *testing.T) { t.Errorf("Notify was not called when BeforeNotify panicked") } } + +func TestHttpRequestMiddleware(t *testing.T) { + var req *http.Request + rawData := []interface{}{req} + + event := &Event{RawData: rawData} + config := &Configuration{} + err := httpRequestMiddleware(event, config) + if err != nil { + t.Errorf("Should not happen") + } +} From d528c5bd97cb9f6e09cac6ae7bd8ad17ebbf738f Mon Sep 17 00:00:00 2001 From: Daria Bialobrzeska Date: Tue, 20 Feb 2024 12:14:28 +0100 Subject: [PATCH 5/6] Add info to CHANGELOG --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45c50b9b..0dda7bfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 2.2.1 (2022-02-21) + +### Bug fixes + +* Fix middleware panic on nil *http.Request + [#212](https://github.com/bugsnag/bugsnag-go/pull/212) + ## 2.2.0 (2022-10-12) ### Enhancements From 8754ab33441c767bf724890e8b9ce6c9919552ba Mon Sep 17 00:00:00 2001 From: Daria Bialobrzeska Date: Wed, 21 Feb 2024 10:39:04 +0100 Subject: [PATCH 6/6] Update version in bugsnag.go to 2.2.1 --- v2/bugsnag.go | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/v2/bugsnag.go b/v2/bugsnag.go index d35d82a0..deef53cd 100644 --- a/v2/bugsnag.go +++ b/v2/bugsnag.go @@ -21,7 +21,7 @@ import ( ) // Version defines the version of this Bugsnag notifier -const Version = "2.2.0" +const Version = "2.2.1" var panicHandlerOnce sync.Once var sessionTrackerOnce sync.Once @@ -91,11 +91,13 @@ func Notify(err error, rawData ...interface{}) error { // The rawData is used to send extra information along with any // panics that are handled this way. // Usage: -// go func() { -// ctx := bugsnag.StartSession(context.Background()) -// defer bugsnag.AutoNotify(ctx) -// // (possibly crashy code) -// }() +// +// go func() { +// ctx := bugsnag.StartSession(context.Background()) +// defer bugsnag.AutoNotify(ctx) +// // (possibly crashy code) +// }() +// // See also: bugsnag.Recover() func AutoNotify(rawData ...interface{}) { if err := recover(); err != nil { @@ -122,18 +124,22 @@ func AutoNotify(rawData ...interface{}) { // The rawData is used to send extra information along with // any panics that are handled this way // Usage: -// go func() { -// ctx := bugsnag.StartSession(context.Background()) -// defer bugsnag.Recover(ctx) -// // (possibly crashy code) -// }() +// +// go func() { +// ctx := bugsnag.StartSession(context.Background()) +// defer bugsnag.Recover(ctx) +// // (possibly crashy code) +// }() +// // If you wish that any panics caught by the call to Recover shall affect your // stability score (it does not by default): -// go func() { -// ctx := bugsnag.StartSession(context.Background()) -// defer bugsnag.Recover(ctx, bugsnag.HandledState{Unhandled: true}) -// // (possibly crashy code) -// }() +// +// go func() { +// ctx := bugsnag.StartSession(context.Background()) +// defer bugsnag.Recover(ctx, bugsnag.HandledState{Unhandled: true}) +// // (possibly crashy code) +// }() +// // See also: bugsnag.AutoNotify() func Recover(rawData ...interface{}) { if err := recover(); err != nil {