{"record":{"id":"adac51aa8586def1","repo":"Intervention/image","slug":"unable-to-parse-hsl-color-from-input-input","errorCode":null,"errorMessage":"Unable to parse HSL color from input \"{input}\"","messagePattern":"Unable to parse HSL color from input \"(.+?)\"","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Colors/Hsl/Color.php","lineNumber":64,"sourceCode":"    public static function create(int|Hue $h, int|Saturation $s, int|Luminance $l, float|Alpha $a = 1): self\n    {\n        return new self($h, $s, $l, $a);\n    }\n\n    /**\n     * Parse HSL 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 HSL 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/Hsl/Color.php#L46-L82","documentation":"Hsl\\Color::parse() only accepts strings decodable by the HSL string color decoder, which requires the input to start with 'hsl' (e.g. 'hsl(0, 100%, 50%)' or 'hsla(0, 100%, 50% / 0.5)'). When no registered decoder can handle the input, the resulting NotSupportedException/DriverException is wrapped in this InvalidArgumentException repeating the offending input. Note: a string that starts with 'hsl' but is malformed throws the different error 'Invalid hsl() color syntax'.","triggerScenarios":"Hsl\\Color::parse('#ff0000'), Hsl\\Color::parse('rgb(255, 0, 0)'), Hsl\\Color::parse('red'), Hsl\\Color::parse('') - none start with 'hsl', so the decoder's supports() check fails and the InputHandler throws, which parse() wraps. Also non-string or whitespace-padded input.","commonSituations":"Storing colors as hex/RGB in a database or config and passing them to the HSL-specific parser; generic user input funneled into a colorspace-specific parse method; whitespace or BOM prefixes from templates or CSV files.","solutions":["Pass HSL syntax: Hsl\\Color::parse('hsl(0, 100%, 50%)')","For hex/rgb/named input, parse with Rgb\\Color::parse() (or the generic color parser) and convert: $color->toColorspace(Hsl\\Colorspace::class)","Trim the input before parsing: Hsl\\Color::parse(trim($input))","If accepting arbitrary user input, validate the prefix and fall back to a default color instead of failing"],"exampleFix":"// before\n$hsl = Hsl\\Color::parse('#ff0000');\n\n// after\n$hsl = Rgb\\Color::parse('#ff0000')->toColorspace(Hsl\\Colorspace::class);\n// or use correct syntax directly:\n$hsl = Hsl\\Color::parse('hsl(0, 100%, 50%)');","handlingStrategy":"validation","validationCode":"$trimmed = trim((string) $input);\nif (!str_starts_with(strtolower($trimmed), 'hsl')) {\n    // not parseable by Hsl\\Color::parse(); route hex/rgb via Rgb\\Color::parse()\n}","typeGuard":"function isHslParseable(mixed $input): bool\n{\n    return is_string($input) && str_starts_with(strtolower(trim($input)), 'hsl');\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException as ImageArg;\n\ntry {\n    $hsl = Hsl\\Color::parse($input);\n} catch (ImageArg $e) {\n    $hsl = Rgb\\Color::parse($input)->toColorspace(Hsl\\Colorspace::class);\n}","preventionTips":["Match the parser to the stored format: hex/rgb -> Rgb\\Color::parse, then convert","Trim user input before parsing","Wrap parse calls that accept arbitrary formats with an Rgb fallback"],"tags":["php","intervention-image","color","hsl","string-parsing","validation"],"backgroundTag":"color-string-parse-error","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}