{"record":{"id":"c808ff8f6a1acf5c","repo":"cakephp/cakephp","slug":"file-not-found-s","errorCode":null,"errorMessage":"File not found: `%s`","messagePattern":"File not found: `(.+?)`","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Mailer/Message.php","lineNumber":1190,"sourceCode":"            if (!isset($fileInfo['file'])) {\n                if (!isset($fileInfo['data'])) {\n                    throw new InvalidArgumentException('No file or data specified.');\n                }\n                if (is_int($name)) {\n                    throw new InvalidArgumentException('No filename specified.');\n                }\n                $fileInfo['data'] = chunk_split(base64_encode($fileInfo['data']), 76, \"\\r\\n\");\n            } elseif ($fileInfo['file'] instanceof UploadedFileInterface) {\n                $fileInfo['mimetype'] = $fileInfo['file']->getClientMediaType();\n                if (is_int($name)) {\n                    $name = $fileInfo['file']->getClientFilename();\n                    assert(is_string($name));\n                }\n            } elseif (is_string($fileInfo['file'])) {\n                $fileName = $fileInfo['file'];\n                $fileInfo['file'] = realpath($fileInfo['file']);\n                if ($fileInfo['file'] === false || !file_exists($fileInfo['file'])) {\n                    throw new InvalidArgumentException(sprintf('File not found: `%s`', $fileName));\n                }\n                if (is_int($name)) {\n                    $name = basename($fileInfo['file']);\n                }\n            } else {\n                throw new InvalidArgumentException(sprintf(\n                    'File must be a filepath or UploadedFileInterface instance. Found `%s` instead.',\n                    gettype($fileInfo['file']),\n                ));\n            }\n            if (\n                !isset($fileInfo['mimetype'])\n                && isset($fileInfo['file'])\n                && is_string($fileInfo['file'])\n                && function_exists('mime_content_type')\n            ) {\n                $fileInfo['mimetype'] = mime_content_type($fileInfo['file']);\n            }","sourceCodeStart":1172,"sourceCodeEnd":1208,"githubUrl":"https://github.com/cakephp/cakephp/blob/1128eba9b09f1946df684811350e26f2cef68fac/src/Mailer/Message.php#L1172-L1208","documentation":"When an attachment's 'file' value is a string path, setAttachments() resolves it with realpath() and checks file_exists(); if the path cannot be resolved or the file does not exist, it throws InvalidArgumentException('File not found: `%s`') with the original path.","triggerScenarios":"Attaching a path that is wrong, deleted, unreadable due to symlinks broken, or relative to a different working directory than expected. Called via addAttachments()/setAttachments().","commonSituations":"Relative paths resolving differently under CLI vs web SAPI (different CWD); files generated in a previous step that failed; temp files already cleaned up; typo in path; Docker containers missing the file.","solutions":["Verify the path exists with file_exists()/is_readable() before attaching","Use absolute paths (realpath()/ROOT constants) instead of relative","Check that the file-generation step succeeded before building attachments","Inspect the printed path in the message to catch typos"],"exampleFix":"// before\n$message->setAttachments([LOGS . 'missing.log']);\n// after\n$path = LOGS . 'report.log';\nif (!is_file($path)) { throw new RuntimeException(\"Missing attachment: $path\"); }\n$message->setAttachments([$path]);","handlingStrategy":"validation","validationCode":"$path = realpath($candidate);\nif ($path === false || !is_file($path) || !is_readable($path)) {\n    throw new \\RuntimeException(\"Attachment file missing/unreadable: $candidate\");\n}\n$message->setAttachments([$path]);","typeGuard":"function attachableFile(mixed $file): ?string {\n    $p = is_string($file) ? realpath($file) : false;\n    return ($p !== false && is_file($p) && is_readable($p)) ? $p : null;\n}","tryCatchPattern":"try {\n    $message->setAttachments($attachments);\n} catch (\\InvalidArgumentException $e) {\n    $this->logger->warning('Skipping missing attachment: ' . $e->getMessage());\n    // send without the missing file\n}","preventionTips":["Use absolute paths (ROOT/LOGS/constants) instead of CWD-relative ones","Confirm file-generating steps succeeded before emailing","Check tmp file lifetimes — don't attach already-cleaned temp files","Verify files exist inside containers/volumes"],"tags":["cakephp","email","attachments","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"1128eba9b09f1946df684811350e26f2cef68fac","analyzedAt":"2026-09-12T12:07:00.388Z","contentChangedAt":"2026-09-12T12:07:00.388Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}