laravel/framework · error · FileNotFoundException
File does not exist at path
Error message
File does not exist at path {$path}. What it means
Thrown by Filesystem::get($path) when is_file($path) returns false — the path does not point to an existing regular file. This is the low-level Illuminate\Filesystem\Filesystem (not the cloud adapter); it reads local disk. The exception is Illuminate\Contracts\Filesystem\FileNotFoundException.
Solutions
- Guard the read with File::exists($path) or File::isFile($path) before calling get().
- Correct the path: prefer absolute paths built via base_path()/storage_path()/app_path().
- In tests, use Illuminate\Filesystem::cleanDirectory/copy fixtures so the file actually exists before assertion.
- Catch FileNotFoundException where missing files are a legitimate runtime condition (e.g., optional cache).
Example fix
// before
$contents = File::get($path);
// after
if (File::exists($path)) {
$contents = File::get($path);
} Defensive patterns
Strategy: validation
Validate before calling
use Illuminate\Filesystem\Filesystem;
if (app(Filesystem::class)->exists($path)) {
return app(Filesystem::class)->get($path);
} Type guard
function isReadableFile(string $path): bool {
return is_file($path) && is_readable($path);
} Try / catch
use Illuminate\Contracts\Filesystem\FileNotFoundException;
try {
$contents = File::get($path);
} catch (FileNotFoundException $e) {
report($e);
return $fallback;
} Prevention
- Always check File::exists() before File::get().
- Prefer absolute paths via storage_path()/base_path().
- In tests, create fixture files in setUp().
- Treat FileNotFoundException as recoverable for optional files.
When it happens
Trigger: Calling File::get($path) (or app('files')->get($path)) where $path is missing, is a directory, is a broken symlink, or points outside reachable storage due to a wrong base path.
Common situations: Reading config/cache files that were cleared; wrong relative path during testing; file deleted between existence check and read (TOCTOU); container path not mounted; typo in storage_path()/base_path() concatenation.
Related errors
- Database file at path
- Disk [ ] does not have a configured driver.
- Driver [ ] is not supported.
- Scoped disk is missing "disk" configuration option.
- Scoped disk is missing "prefix" configuration option.
AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11).
Data as JSON: /api/errors/2102d86a0727aa68.
Report an issue: GitHub.
Appendix: source
Thrown at src/Illuminate/Filesystem/Filesystem.php:58
return ! $this->exists($path);
}
/**
* Get the contents of a file.
*
* @param string $path
* @param bool $lock
* @return string
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function get($path, $lock = false)
{
if ($this->isFile($path)) {
return $lock ? $this->sharedGet($path) : file_get_contents($path);
}
throw new FileNotFoundException("File does not exist at path {$path}.");
}
/**
* Get the contents of a file as decoded JSON.
*
* @param string $path
* @param int $flags
* @param bool $lock
* @return array
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function json($path, $flags = 0, $lock = false)
{
return json_decode($this->get($path, $lock), true, 512, $flags);
}
/**View on GitHub (pinned to e0f6eb3518)