From d8881ecd3a432310141cdb05f518cb779ed234da Mon Sep 17 00:00:00 2001 From: Arkadiy Kukarkin Date: Thu, 23 Apr 2026 16:30:00 +0200 Subject: [PATCH] dataprep: check Find err before empty-slice, use %s for string id Two issues in ListPiecesHandler: 1. The error from Find(&sourceAttachments) was checked after the len==0 guard, so a real DB error (connection lost, timeout) was mapped to a 404 'preparation not found' instead of propagating. 2. The 'not found' format string used %d against the string handler argument id, producing 'preparation %!d(string=foo) not found'. --- handler/dataprep/piece.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/handler/dataprep/piece.go b/handler/dataprep/piece.go index 4c28e37fd..bde0d64f9 100644 --- a/handler/dataprep/piece.go +++ b/handler/dataprep/piece.go @@ -63,12 +63,12 @@ func (DefaultHandler) ListPiecesHandler( } var sourceAttachments []model.SourceAttachment err = db.Preload("Storage").Where("preparation_id = ?", preparation.ID).Find(&sourceAttachments).Error - if len(sourceAttachments) == 0 { - return nil, errors.Wrapf(handlererror.ErrNotFound, "preparation %d not found", id) - } if err != nil { return nil, errors.WithStack(err) } + if len(sourceAttachments) == 0 { + return nil, errors.Wrapf(handlererror.ErrNotFound, "preparation %s not found", id) + } var pieceLists []PieceList for _, sourceAttachment := range sourceAttachments {