mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-06-17 22:37:33 +02:00
Better stacktrace of processing errorf
This commit is contained in:
11
errors.go
11
errors.go
@ -20,14 +20,17 @@ func newError(status int, msg string, pub string) *imgproxyError {
|
|||||||
return &imgproxyError{status, msg, pub}
|
return &imgproxyError{status, msg, pub}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newUnexpectedError(err error, skip int) *imgproxyError {
|
func newUnexpectedError(msg string, skip int) *imgproxyError {
|
||||||
msg := fmt.Sprintf("Unexpected error: %s\n%s", err, stacktrace(skip+1))
|
return &imgproxyError{
|
||||||
return &imgproxyError{500, msg, "Internal error"}
|
500,
|
||||||
|
fmt.Sprintf("Unexpected error: %s\n%s", msg, stacktrace(skip+3)),
|
||||||
|
"Internal error",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func stacktrace(skip int) string {
|
func stacktrace(skip int) string {
|
||||||
callers := make([]uintptr, 10)
|
callers := make([]uintptr, 10)
|
||||||
n := runtime.Callers(skip+1, callers)
|
n := runtime.Callers(skip, callers)
|
||||||
|
|
||||||
lines := make([]string, n)
|
lines := make([]string, n)
|
||||||
for i, pc := range callers[:n] {
|
for i, pc := range callers[:n] {
|
||||||
|
@ -1048,5 +1048,5 @@ func vipsApplyWatermark(img **C.VipsImage, opts *watermarkOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func vipsError() error {
|
func vipsError() error {
|
||||||
return errors.New(C.GoString(C.vips_error_buffer()))
|
return newUnexpectedError(C.GoString(C.vips_error_buffer()), 1)
|
||||||
}
|
}
|
||||||
|
@ -240,7 +240,7 @@ func (h *httpHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
|||||||
if ierr, ok := err.(*imgproxyError); ok {
|
if ierr, ok := err.(*imgproxyError); ok {
|
||||||
respondWithError(reqID, rw, ierr)
|
respondWithError(reqID, rw, ierr)
|
||||||
} else {
|
} else {
|
||||||
respondWithError(reqID, rw, newUnexpectedError(err, 4))
|
respondWithError(reqID, rw, newUnexpectedError(err.Error(), 3))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
panic(rerr)
|
panic(rerr)
|
||||||
|
Reference in New Issue
Block a user