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

panic middleware does not report the stack trace #162

Closed
komuw opened this issue Oct 21, 2022 · 0 comments · Fixed by #164
Closed

panic middleware does not report the stack trace #162

komuw opened this issue Oct 21, 2022 · 0 comments · Fixed by #164

Comments

@komuw
Copy link
Owner

komuw commented Oct 21, 2022

func anotherHandlerThatPanics() http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		_ = 90
		someSlice := []string{"zero", "one", "two"}
		_ = "kilo"
		_ = someSlice[16] // panic

		fmt.Fprint(w, "anotherHandlerThatPanics")
	}
}

test {
               logOutput := &bytes.Buffer{}
		wrappedHandler := Panic(anotherHandlerThatPanics(), getLogger(logOutput))

		rec := httptest.NewRecorder()
		req := httptest.NewRequest(http.MethodGet, "/someUri", nil)
		wrappedHandler.ServeHTTP(rec, req)

		res := rec.Result()
		defer res.Body.Close()
		attest.Equal(t, res.StatusCode, http.StatusInternalServerError)
		// attest.Zero(t, logOutput.String())
		fmt.Println("logOutput.String():::")
		fmt.Println(logOutput.String())
}

//
{
"code":500,"err":"runtime error: index out of range [16] with length 3",
"level":"error",
"line":"/home/komuw/mystuff/ong/middleware/panic.go:50",
"logID":"xrZKzxpH7XMtkegRMmTQ8w",
"method":"GET",
"path":"/someUri",
"pid":1349746,
"requestAddr":"192.0.2.1:1234",
"status":"Internal Server Error",
"timestamp":"2022-10-21T07:05:20.778620076Z"
}
komuw added a commit that referenced this issue Oct 21, 2022
What:
- Panic middleware should include correct stack trace.

Why:
- Fixes: #162
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant