{"record":{"id":"25e3fffcd2be9d17","repo":"Intervention/image","slug":"unable-to-parse-hsv-color-from-input-input","errorCode":null,"errorMessage":"Unable to parse HSV color from input \"{input}\"","messagePattern":"Unable to parse HSV color from input \"(.+?)\"","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Colors/Hsv/Color.php","lineNumber":64,"sourceCode":"    public static function create(int|Hue $h, int|Saturation $s, int|Value $v, float|Alpha $a = 1): self\n    {\n        return new self($h, $s, $v, $a);\n    }\n\n    /**\n     * Parse HSV 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 HSV 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/Hsv/Color.php#L46-L82","documentation":"Hsv\\Color::parse() accepts only strings decodable by the HSV string color decoder, i.e. input beginning with 'hsv' such as 'hsv(120, 100%, 50%)'. If no decoder supports the input, the NotSupportedException/DriverException from the input handler is wrapped in this InvalidArgumentException repeating the input. A string that starts with 'hsv' but is malformed produces the separate 'Invalid hsv() color syntax' error instead.","triggerScenarios":"Hsv\\Color::parse('#00ff00'), Hsv\\Color::parse('rgb(0, 255, 0)'), Hsv\\Color::parse('green'), Hsv\\Color::parse('') - none start with 'hsv'; also leading whitespace or a BOM in front of an otherwise valid string.","commonSituations":"Passing hex/RGB values from databases or config into the HSV-specific parser; generic user input routed to the wrong colorspace-specific parse method; template/CSV sources adding invisible leading characters.","solutions":["Use HSV syntax: Hsv\\Color::parse('hsv(120, 100%, 50%)')","Parse hex/rgb with Rgb\\Color::parse() and convert: ->toColorspace(Hsv\\Colorspace::class)","Trim input before parsing","Route arbitrary formats through a generic parser and convert afterwards, instead of the HSV-specific one"],"exampleFix":"// before\n$hsv = Hsv\\Color::parse('#00ff00');\n\n// after\n$hsv = Rgb\\Color::parse('#00ff00')->toColorspace(Hsv\\Colorspace::class);","handlingStrategy":"validation","validationCode":"$trimmed = trim((string) $input);\nif (!str_starts_with(strtolower($trimmed), 'hsv')) {\n    // not parseable by Hsv\\Color::parse(); use Rgb\\Color::parse() + conversion\n}","typeGuard":"function isHsvParseable(mixed $input): bool\n{\n    return is_string($input) && str_starts_with(strtolower(trim($input)), 'hsv');\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException as ImageArg;\n\ntry {\n    $hsv = Hsv\\Color::parse($input);\n} catch (ImageArg $e) {\n    $hsv = Rgb\\Color::parse($input)->toColorspace(Hsv\\Colorspace::class);\n}","preventionTips":["Route hex/rgb/named formats through Rgb\\Color::parse() and convert","Trim input before parsing","Centralize color-string parsing in one helper so formats cannot be mismatched"],"tags":["php","intervention-image","color","hsv","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"}