{"record":{"id":"79dc81dbdde074ee","repo":"Intervention/image","slug":"unable-to-decode-from-null","errorCode":null,"errorMessage":"Unable to decode from null","messagePattern":"Unable to decode from null","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/InputHandler.php","lineNumber":101,"sourceCode":"     */\n    public static function usingDecoders(array $decoders, ?DriverInterface $driver = null): self\n    {\n        return new self($decoders, $driver);\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see InputHandlerInterface::handle()\n     *\n     * @throws InvalidArgumentException\n     * @throws NotSupportedException\n     * @throws DriverException\n     */\n    public function handle(mixed $input): ImageInterface|ColorInterface\n    {\n        if ($input === null) {\n            throw new InvalidArgumentException('Unable to decode from null');\n        }\n\n        if ($input === '') {\n            throw new InvalidArgumentException('Unable to decode from empty string');\n        }\n\n        // if handler has only one single decoder run it can run directly\n        if (count($this->decoders) === 1) {\n            return $this->decoders()->current()->decode($input);\n        }\n\n        // multiple decoders: try to find the matching decoder for the input\n        foreach ($this->decoders() as $decoder) {\n            if ($decoder->supports($input)) {\n                return $decoder->decode($input);\n            }\n        }\n","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/InputHandler.php#L83-L119","documentation":"InputHandler::handle() is the funnel behind ImageManager::read()/parse() and color parsing; it rejects null outright because there is no decoder for 'nothing'. The check precedes decoder selection, so it fires before any 'Unprocessable input' logic. Receiving this error means your code passed a null variable into the read pipeline — typically a missing upload, an absent config value, or a failed lookup.","triggerScenarios":"$manager->read(null), $manager->read($request->file('avatar')) when no file was uploaded (Laravel returns null), read($cache->get('image')) on cache miss, or parse(null) in color handling flows.","commonSituations":"HTTP endpoints processing optional uploads without presence checks, cache/session lookups that return null, or array access on missing keys under permissive fetch. Common after refactoring when a variable that was always set becomes conditional.","solutions":["Check for null before reading: if ($file = $request->file('avatar')) { ... }","Use strict access ($array['key'] ?? null) and branch on the result instead of passing it through","For optional uploads, skip processing entirely when the input is absent rather than relying on the library to validate","Add a typed intermediary: function readImage(mixed $src): ImageInterface that throws your own descriptive error on null"],"exampleFix":"// before\n$image = $manager->read($request->file('avatar')); // null when no upload\n\n// after\nif (null === ($file = $request->file('avatar'))) {\n    abort(422, 'Avatar upload is required.');\n}\n$image = $manager->read($file->getPathname());","handlingStrategy":"validation","validationCode":"$source = $request->file('avatar')?->getPathname();\nif ($source === null) {\n    abort(422, 'Avatar upload is required.');\n}\n$image = $manager->read($source);","typeGuard":"function isReadableInput(mixed $input): bool\n{\n    return $input !== null && $input !== '';\n}","tryCatchPattern":"try {\n    $image = $manager->read($input);\n} catch (InvalidArgumentException $e) {\n    // null input is a caller bug: fail with a clear 422, never retry\n}","preventionTips":["Check upload presence before calling read(); do not rely on the library to validate","Use null-safe access (?->) when chaining optional lookups","Default cache/config lookups to a sentinel and branch, instead of passing null through"],"tags":["input","decoder","read","validation","upload"],"backgroundTag":"null-input-rejected","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}