{"record":{"id":"b5e370029a492111","repo":"Intervention/image","slug":"path-must-not-be-an-empty-string","errorCode":null,"errorMessage":"Path must not be an empty string","messagePattern":"Path must not be an empty string","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/File.php","lineNumber":75,"sourceCode":"        }\n\n        return new self($stream);\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see FileInterface::save()\n     *\n     * @throws InvalidArgumentException\n     * @throws DirectoryNotFoundException\n     * @throws FileNotWritableException\n     * @throws StreamException\n     */\n    public function save(string $path): void\n    {\n        if ($path === '') {\n            throw new InvalidArgumentException('Path must not be an empty string');\n        }\n\n        if (strlen($path) > PHP_MAXPATHLEN) {\n            throw new InvalidArgumentException(\n                \"Path is longer than the configured max. value of \" . PHP_MAXPATHLEN,\n            );\n        }\n\n        $dir = pathinfo($path, PATHINFO_DIRNAME);\n\n        if (!is_dir($dir)) {\n            throw new DirectoryNotFoundException(\n                'Can\\'t write to path. Directory \"' . $dir . '\" does not exist',\n            );\n        }\n\n        if (!is_writable($dir)) {\n            throw new FileNotWritableException(","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/File.php#L57-L93","documentation":"File::save() refuses an empty target path with InvalidArgumentException before touching the filesystem. You reach this through the EncodedImage/File API - $image->encode(...)->save('') - because the higher-level Image::save() has its own identical guard and would throw earlier. It almost always means a path variable that was assembled from missing input collapsed to an empty string.","triggerScenarios":"Calling $encodedImage->save($path) where $path is '' - e.g. a config key that returned null and was cast to string, or a request parameter that was present but empty.","commonSituations":"Optional request/config path inputs not validated for emptiness; string concatenation where every part was empty; code paths where the filename variable was never set before use.","solutions":["Guard for the empty string before calling save() and fail with your own clear error","Provide a default output path when the dynamic part is missing","Validate path inputs at the application boundary (required, min length)"],"exampleFix":"// before\n$encoded->save($config->get('output_path') ?? ''); // '' when unset\n\n// after\n$path = $config->get('output_path');\nif ($path === null || $path === '') {\n    throw new RuntimeException('Output path is not configured');\n}\n$encoded->save($path);","handlingStrategy":"validation","validationCode":"if ($path === '') {\n    throw new InvalidArgumentException('Output path must not be empty');\n}\n$encoded->save($path);","typeGuard":"function isNonEmptyPath(mixed $path): bool\n{\n    return is_string($path) && $path !== '';\n}","tryCatchPattern":null,"preventionTips":["Validate path inputs as required at the request boundary","Never coalesce missing config to '' when building output paths","Fail with your own descriptive error before calling save()"],"tags":["php","intervention-image","file","save","path","invalid-argument"],"backgroundTag":"empty-string-argument","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}