Skip to content

Commit

Permalink
Merge pull request #1333 from Azure/let-unit-tests-panic
Browse files Browse the repository at this point in the history
frontend: Do not handle panics when running "go test"
  • Loading branch information
mbarnes authored Feb 17, 2025
2 parents 6c4a5e1 + 0cab644 commit aa7fc49
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions frontend/pkg/frontend/middleware_panic.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ import (
"fmt"
"net/http"
"runtime/debug"
"testing"

"github.com/Azure/ARO-HCP/internal/api/arm"
)

func MiddlewarePanic(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
defer func() {
if e := recover(); e != nil {
logger := LoggerFromContext(r.Context())
logger.Error(fmt.Sprintf("panic: %#v\n%s\n", e, string(debug.Stack())))
arm.WriteInternalServerError(w)
}
}()
// Do not catch panics when running "go test".
if !testing.Testing() {
defer func() {
if e := recover(); e != nil {
logger := LoggerFromContext(r.Context())
logger.Error(fmt.Sprintf("panic: %#v\n%s\n", e, string(debug.Stack())))
arm.WriteInternalServerError(w)
}
}()
}

next(w, r)
}

0 comments on commit aa7fc49

Please sign in to comment.