{"record":{"id":"8f3bbd9696667063","repo":"Intervention/image","slug":"argument-path-must-not-be-an-empty-string","errorCode":null,"errorMessage":"Argument $path must not be an empty string","messagePattern":"Argument \\$path must not be an empty string","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Image.php","lineNumber":309,"sourceCode":"        return $this->driver()->specializeAnalyzer($analyzer)->analyze($this);\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see ImageInterface::save()\n     *\n     * @throws InvalidArgumentException\n     * @throws EncoderException\n     * @throws DirectoryNotFoundException\n     * @throws FileNotWritableException\n     * @throws StreamException\n     * @throws NotSupportedException\n     */\n    public function save(?string $path = null, mixed ...$options): ImageInterface\n    {\n        if ($path === '') {\n            throw new InvalidArgumentException('Argument $path must not be an empty string');\n        }\n\n        if (is_null($path) && is_null($this->origin()->filePath())) {\n            throw new EncoderException('Unable to determine path for saving');\n        }\n\n        $path = is_null($path) ? $this->origin()->filePath() : $path;\n\n        try {\n            // try to determine encoding format by file extension of the path\n            $encoded = $this->encode(new FilePathEncoder($path, ...$options));\n        } catch (EncoderException) {\n            // fallback to encoding format by media type\n            $encoded = $this->encode(new MediaTypeEncoder(null, ...$options));\n        }\n\n        $encoded->save($path);\n","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Image.php#L291-L327","documentation":"Image::save() treats an empty string as an explicitly invalid path, distinct from null. Passing null means 'reuse the original file path from the image origin', while '' is almost certainly a bug — typically an unset variable or missing user input coerced to a string. The check runs before any encoding work, so nothing is written when it throws.","triggerScenarios":"$image->save('') — e.g. save($request->input('path')), save($config['output'] ?? '') or save($filename) where $filename was initialized to '' and never set. Note save(null) is valid when the image has a file origin.","commonSituations":"Form/config values defaulting to empty string instead of null, path variables reset in loops, or string interpolation producing '' — common in Laravel controller code feeding request input straight to save().","solutions":["Pass null (not '') when you want to save back to the original file path","Default missing user input to null: $request->input('path') returns null when absent — avoid ?? '' overrides","Validate: if ($path === '') { abort / use fallback path } before calling save()","Initialize path variables to null rather than '' so the origin-fallback logic can work"],"exampleFix":"// before\n$path = $request->input('path') ?? '';\n$image->save($path); // throws when input missing\n\n// after\n$path = $request->input('path'); // null when absent\n$image->save($path); // falls back to original file path","handlingStrategy":"validation","validationCode":"$path = $request->input('path'); // null, not ''\nif ($path === '') {\n    $path = null; // let save() fall back to the origin path\n}\n$image->save($path);","typeGuard":"function isSaveablePath(?string $path): bool\n{\n    return $path === null || $path !== '';\n}","tryCatchPattern":"try {\n    $image->save($path);\n} catch (InvalidArgumentException $e) {\n    // empty-string bug in caller: fix the caller, do not retry\n}","preventionTips":["Default path variables to null, never ''","Avoid ?? '' overrides on request/config lookups feeding save()","Add a save-path unit assertion in controller tests"],"tags":["save","path","validation","filesystem"],"backgroundTag":"empty-string-argument","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}