From 88e6ce48447ff5b643aed55157a59178b26c834d Mon Sep 17 00:00:00 2001 From: kobergj Date: Tue, 28 Jul 2026 21:01:24 +0200 Subject: [PATCH] fix(webdav): log unmapped thumbnail errors at error level (#12663) (#12666) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 . (cherry picked from commit 6950f47885ebafce53aec2b499c2f4c58989d713) Co-authored-by: Claude Opus 5 --- .../fix-webdav-thumbnail-error-logging.md | 18 +++++++ services/webdav/pkg/service/v0/service.go | 33 ++++++++++-- .../webdav/pkg/service/v0/service_test.go | 50 +++++++++++++++++++ 3 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/fix-webdav-thumbnail-error-logging.md create mode 100644 services/webdav/pkg/service/v0/service_test.go diff --git a/changelog/unreleased/fix-webdav-thumbnail-error-logging.md b/changelog/unreleased/fix-webdav-thumbnail-error-logging.md new file mode 100644 index 00000000000..ff998f2536e --- /dev/null +++ b/changelog/unreleased/fix-webdav-thumbnail-error-logging.md @@ -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 `` +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 diff --git a/services/webdav/pkg/service/v0/service.go b/services/webdav/pkg/service/v0/service.go index 33c0550d959..1ccba48317d 100644 --- a/services/webdav/pkg/service/v0/service.go +++ b/services/webdav/pkg/service/v0/service.go @@ -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 diff --git a/services/webdav/pkg/service/v0/service_test.go b/services/webdav/pkg/service/v0/service_test.go new file mode 100644 index 00000000000..b654c50c863 --- /dev/null +++ b/services/webdav/pkg/service/v0/service_test.go @@ -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) + } +}