{"record":{"id":"3cfab7a3efb4118d","repo":"Intervention/image","slug":"unable-to-parse-oklab-color-from-input-input","errorCode":null,"errorMessage":"Unable to parse OKLAB color from input \"{input}\"","messagePattern":"Unable to parse OKLAB color from input \"(.+?)\"","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Colors/Oklab/Color.php","lineNumber":64,"sourceCode":"    public static function create(float|Lightness $l, float|A $a, float|B $b, float|Alpha $alpha = 1): self\n    {\n        return new self($l, $a, $b, $alpha);\n    }\n\n    /**\n     * Parse OKLAB color from string.\n     *\n     * @throws InvalidArgumentException\n     * @throws ColorException\n     */\n    public static function parse(string $input): self\n    {\n        try {\n            $color = InputHandler::usingDecoders([\n                StringColorDecoder::class,\n            ])->handle($input);\n        } catch (NotSupportedException | DriverException $e) {\n            throw new InvalidArgumentException(\n                'Unable to parse OKLAB color from input \"' . $input . '\"',\n                previous: $e,\n            );\n        }\n\n        if (!$color instanceof self) {\n            throw new ColorException('Result must be instance of ' . self::class);\n        }\n\n        return $color;\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see ColorInterface::colorspace()\n     */\n    public function colorspace(): ColorspaceInterface","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Colors/Oklab/Color.php#L46-L82","documentation":"Oklab\\Color::parse() pushes the input through an InputHandler configured with only the OKLAB StringColorDecoder; if that pipeline reports it cannot process the input (NotSupportedException) or a decoder cannot be resolved (DriverException), the failure is rethrown as this InvalidArgumentException (src/Colors/Oklab/Color.php:57-68). Note that a well-formed-but-malformed 'oklab(...)' string instead surfaces the more specific 'Invalid oklab() color syntax' error from the decoder itself.","triggerScenarios":"Calling Oklab\\Color::parse() with input the registered decoder chain rejects (e.g. a hex string, a color name, or a non-'oklab(...)' format reaching the handler path that throws NotSupportedException 'Unprocessable input').","commonSituations":"Passing '#ff5500', 'red' or an 'hsl(...)' string to the OKLAB-specific parse() instead of the generic color parser; assuming parse() accepts any color format rather than only oklab() strings.","solutions":["Use the oklab(...) string format: 'oklab(0.5, 0.1, 0.1)' or 'oklab(50% 0.1 0.1 / 0.5)'","For other formats, parse with the generic driver color pipeline or the matching colorspace's Color::parse() first, then convert with toColorspace()","For programmatic values, construct directly: Oklab\\Color::create(0.5, 0.1, 0.1)","Catch InvalidArgumentException around parse() when input is user-supplied"],"exampleFix":"// before\n$color = Oklab\\Color::parse('#ff5500'); // not an oklab() string\n\n// after\n$color = Rgb\\Color::parse('#ff5500')->toColorspace(Oklab\\Colorspace::class);\n// or construct directly:\n$color = Oklab\\Color::create(0.5, 0.1, 0.1);","handlingStrategy":"validation","validationCode":"if (!is_string($input) || !preg_match('/^oklab\\s*\\(/i', $input)) {\n    // route to a generic parser or reject before calling Oklab\\Color::parse()\n}","typeGuard":"function looksLikeOklabString(mixed $input): bool\n{\n    return is_string($input) && str_starts_with(strtolower($input), 'oklab');\n}","tryCatchPattern":"try {\n    $color = Oklab\\Color::parse($input);\n} catch (Intervention\\Image\\Exceptions\\InvalidArgumentException $e) {\n    // input was not consumable as oklab(); try generic pipeline or reject\n}","preventionTips":["Match the parser to the format: only pass oklab(...) strings to Oklab\\Color::parse()","For arbitrary color strings, use the driver's generic color decoding and then toColorspace()","Construct Oklab\\Color::create() directly when you already hold numeric channels"],"tags":["color","oklab","string-parsing","colorspace","php"],"backgroundTag":"color-string-parse-error","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}