fix(webdav): log unmapped thumbnail errors at error level (#12663) (#12666)

Failures of the thumbnails service were logged at debug level only, so
errors which are not a property of the requested file — such as the
thumbnails service being unreachable — were invisible at production log
levels. A complete preview outage produced HTTP 500 responses without a
single log line explaining them.

Unmapped errors are now logged at error level, while expected per-file
outcomes such as an unsupported file type or a file still being processed
stay at debug level. Two of the four thumbnail handlers also logged
without the request context, so their messages carried no request id.

Also add the missing codesEnum entries for 403, 425 and 429 and fall back
to a generic exception name for any remaining unmapped status code, so
error responses no longer render an empty <s:exception></s:exception>.


(cherry picked from commit 6950f47885)

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
kobergjandClaude Opus 5 authored and GitHub committed 2026-07-28 21:01:24 +02:00
1 parent 683312afe6
commit 88e6ce4844
3 files changed
+98 -3

No files matched your search

@@ -0,0 +1,18 @@
Bugfix: Log unmapped thumbnail errors and always report a sabredav exception
The webdav service logged failures of the thumbnails service at debug level only.
Errors which are not a property of the requested file, such as the thumbnails
service being unreachable, were therefore invisible at production log levels: a
complete preview outage produced HTTP 500 responses without a single log line
explaining them. Unmapped errors are now logged at error level, while expected
per-file outcomes such as an unsupported file type or a file still being
processed stay at debug level. Two of the four thumbnail handlers also logged
without the request context, so their messages carried no request id.
In addition, `codesEnum` only mapped four status codes, so error responses for
all other codes were rendered with an empty `<s:exception></s:exception>`
element. The missing entries for 403, 425 and 429 have been added and any
remaining unmapped code now falls back to a generic exception name, so clients
always receive a usable exception.
https://github.com/owncloud/ocis/pull/12666
+30 -3
View File
@@ -42,7 +42,14 @@ var (
http.StatusUnauthorized: "Sabre\\DAV\\Exception\\NotAuthenticated",
http.StatusNotFound: "Sabre\\DAV\\Exception\\NotFound",
http.StatusMethodNotAllowed: "Sabre\\DAV\\Exception\\MethodNotAllowed",
http.StatusForbidden: "Sabre\\DAV\\Exception\\Forbidden",
http.StatusTooEarly: "Sabre\\DAV\\Exception\\TooEarly",
http.StatusTooManyRequests: "Sabre\\DAV\\Exception\\TooManyRequests",
}
// defaultException is used for status codes which have no dedicated sabredav
// exception name, so that clients always receive a non-empty exception.
defaultException = "Sabre\\DAV\\Exception"
)
// Service defines the extension handlers.
@@ -268,7 +275,11 @@ func (g Webdav) SpacesThumbnail(w http.ResponseWriter, r *http.Request) {
case http.StatusForbidden:
renderError(w, r, errPermissionDenied(e.Detail))
default:
// an unmapped error is an infrastructure problem, not a property of the
// requested file: log it at error level so it is visible in production.
logger.Error().Err(err).Msg("could not get thumbnail")
renderError(w, r, errInternalError(err.Error()))
return
}
logger.Debug().Err(err).Msg("could not get thumbnail")
return
@@ -366,9 +377,13 @@ func (g Webdav) Thumbnail(w http.ResponseWriter, r *http.Request) {
case http.StatusForbidden:
renderError(w, r, errPermissionDenied(e.Detail))
default:
// an unmapped error is an infrastructure problem, not a property of the
// requested file: log it at error level so it is visible in production.
logger.Error().Err(err).Msg("could not get thumbnail")
renderError(w, r, errInternalError(err.Error()))
return
}
g.log.Error().Err(err).Msg("could not get thumbnail")
logger.Debug().Err(err).Msg("could not get thumbnail")
return
}
@@ -411,9 +426,13 @@ func (g Webdav) PublicThumbnail(w http.ResponseWriter, r *http.Request) {
addRetryAfterHeader(w)
renderError(w, r, errTooManyRequests(e.Detail))
default:
// an unmapped error is an infrastructure problem, not a property of the
// requested file: log it at error level so it is visible in production.
logger.Error().Err(err).Msg("could not get thumbnail")
renderError(w, r, errInternalError(err.Error()))
return
}
g.log.Error().Err(err).Msg("could not get thumbnail")
logger.Debug().Err(err).Msg("could not get thumbnail")
return
}
@@ -456,7 +475,11 @@ func (g Webdav) PublicThumbnailHead(w http.ResponseWriter, r *http.Request) {
addRetryAfterHeader(w)
renderError(w, r, errTooManyRequests(e.Detail))
default:
// an unmapped error is an infrastructure problem, not a property of the
// requested file: log it at error level so it is visible in production.
logger.Error().Err(err).Msg("could not get thumbnail")
renderError(w, r, errInternalError(err.Error()))
return
}
logger.Debug().Err(err).Msg("could not get thumbnail")
return
@@ -542,11 +565,15 @@ type errResponse struct {
}
func newErrResponse(statusCode int, msg string) *errResponse {
exception, ok := codesEnum[statusCode]
if !ok {
exception = defaultException
}
rsp := &errResponse{
HTTPStatusCode: statusCode,
Xmlnsd: "DAV",
Xmlnss: "http://sabredav.org/ns",
Exception: codesEnum[statusCode],
Exception: exception,
}
if msg != "" {
rsp.Message = msg
@@ -0,0 +1,50 @@
package svc
import (
"net/http"
"testing"
)
func TestNewErrResponseException(t *testing.T) {
tests := []struct {
name string
statusCode int
expected string
}{
{"bad request", http.StatusBadRequest, "Sabre\\DAV\\Exception\\BadRequest"},
{"unauthorized", http.StatusUnauthorized, "Sabre\\DAV\\Exception\\NotAuthenticated"},
{"not found", http.StatusNotFound, "Sabre\\DAV\\Exception\\NotFound"},
{"method not allowed", http.StatusMethodNotAllowed, "Sabre\\DAV\\Exception\\MethodNotAllowed"},
{"forbidden", http.StatusForbidden, "Sabre\\DAV\\Exception\\Forbidden"},
{"too early", http.StatusTooEarly, "Sabre\\DAV\\Exception\\TooEarly"},
{"too many requests", http.StatusTooManyRequests, "Sabre\\DAV\\Exception\\TooManyRequests"},
// unmapped codes must still yield a non-empty exception
{"internal server error", http.StatusInternalServerError, defaultException},
{"not implemented", http.StatusNotImplemented, defaultException},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rsp := newErrResponse(tt.statusCode, "some message")
if rsp.Exception != tt.expected {
t.Errorf("expected exception %q, got %q", tt.expected, rsp.Exception)
}
if rsp.HTTPStatusCode != tt.statusCode {
t.Errorf("expected status code %d, got %d", tt.statusCode, rsp.HTTPStatusCode)
}
if rsp.Message != "some message" {
t.Errorf("expected message to be set, got %q", rsp.Message)
}
})
}
}
func TestNewErrResponseEmptyMessage(t *testing.T) {
rsp := newErrResponse(http.StatusNotFound, "")
if rsp.Message != "" {
t.Errorf("expected empty message, got %q", rsp.Message)
}
if rsp.Exception != "Sabre\\DAV\\Exception\\NotFound" {
t.Errorf("unexpected exception %q", rsp.Exception)
}
}