{"record":{"id":"8d1f1a410873efa0","repo":"Intervention/image","slug":"unable-to-parse-oklch-color-from-input-input","errorCode":null,"errorMessage":"Unable to parse OKLCH color from input \"{input}\"","messagePattern":"Unable to parse OKLCH color from input \"(.+?)\"","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Colors/Oklch/Color.php","lineNumber":64,"sourceCode":"    public static function create(float|Lightness $l, float|Chroma $c, float|Hue $h, float|Alpha $a = 1): self\n    {\n        return new self($l, $c, $h, $a);\n    }\n\n    /**\n     * Parse OKLCH 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 OKLCH 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/Oklch/Color.php#L46-L82","documentation":"Oklch\\Color::parse() runs the input through an InputHandler registered with only the OKLCH StringColorDecoder; when that pipeline reports it cannot process the input (NotSupportedException) or the decoder cannot be resolved (DriverException), it is rethrown as this InvalidArgumentException (src/Colors/Oklch/Color.php:57-68). A malformed-but-prefixed 'oklch(...)' string instead surfaces the decoder's own 'Invalid oklch() color syntax' error.","triggerScenarios":"Calling Oklch\\Color::parse() with input the oklch decoder chain rejects, e.g. a hex string, color name, or any non-'oklch(...)' color format pushed through the OKLCH-specific parser.","commonSituations":"Passing '#ff5500' or 'red' to the OKLCH-specific parse() instead of a generic parser; assuming one parse() accepts every color format.","solutions":["Use the oklch(...) string format: 'oklch(0.5, 0.1, 150)'","For other formats, parse with the matching Color::parse() or the generic pipeline and convert with toColorspace()","Construct directly with Oklch\\Color::create(l, c, h)","Wrap parse() in try/catch InvalidArgumentException when input is external"],"exampleFix":"// before\n$color = Oklch\\Color::parse('rgb(255, 85, 0)'); // not an oklch() string\n\n// after\n$color = Rgb\\Color::parse('rgb(255, 85, 0)')->toColorspace(Oklch\\Colorspace::class);\n// or construct directly:\n$color = Oklch\\Color::create(0.65, 0.2, 30);","handlingStrategy":"validation","validationCode":"if (!is_string($input) || !preg_match('/^oklch\\s*\\(/i', $input)) {\n    // do not call Oklch\\Color::parse(); use a generic parser and convert\n}","typeGuard":"function looksLikeOklchString(mixed $input): bool\n{\n    return is_string($input) && str_starts_with(strtolower($input), 'oklch');\n}","tryCatchPattern":"try {\n    $color = Oklch\\Color::parse($input);\n} catch (Intervention\\Image\\Exceptions\\InvalidArgumentException $e) {\n    // input not consumable as oklch(); fall back to generic decoding or reject\n}","preventionTips":["Only feed oklch(...) strings to the OKLCH-specific parser","Convert from other formats via their own parse() plus toColorspace()","Use Oklch\\Color::create() when numeric channels are already available"],"tags":["color","oklch","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"}