From 8a7db52268855576d86e92f44f6253c75f87f140 Mon Sep 17 00:00:00 2001 From: Anton Afanasyeu Date: Fri, 7 Aug 2026 22:15:55 +0200 Subject: [PATCH] Tickets: clearer attachment upload error messages. Co-authored-by: Cursor --- src/TicketAttachmentRepository.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/TicketAttachmentRepository.php b/src/TicketAttachmentRepository.php index 20a125b..d81b49b 100644 --- a/src/TicketAttachmentRepository.php +++ b/src/TicketAttachmentRepository.php @@ -93,8 +93,15 @@ final class TicketAttachmentRepository { if (!$ticket) { throw new RuntimeException('not found'); } - if (($file['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK) { - throw new InvalidArgumentException('upload failed'); + $uploadErr = (int) ($file['error'] ?? UPLOAD_ERR_NO_FILE); + if ($uploadErr !== UPLOAD_ERR_OK) { + $msg = match ($uploadErr) { + UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE => 'file too large (max 16 MiB)', + UPLOAD_ERR_PARTIAL => 'upload incomplete', + UPLOAD_ERR_NO_FILE => 'no file selected', + default => 'upload failed', + }; + throw new InvalidArgumentException($msg); } $size = (int) ($file['size'] ?? 0); if ($size <= 0 || $size > self::MAX_BYTES) {