{"record":{"id":"1c8e18ac9f34ce29","repo":"iOfficeAI/OfficeCLI","slug":"invalid-color-value-original-alpha-must-be-0","errorCode":null,"errorMessage":"Invalid color value: '{original}'. Alpha must be 0-1 (e.g. 0.5) or 0%-100%.","messagePattern":"Invalid color value: '(.+?)'\\. Alpha must be 0-1 \\(e\\.g\\. 0\\.5\\) or 0%-100%\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/ParseHelpers.cs","lineNumber":186,"sourceCode":"            throw new ArgumentException($\"Invalid color value: '{original}'. RGB components must be 0-255.\");\n        return (byte)n;\n    }\n\n    private static byte ParseAlphaComponent(string token, string original)\n    {\n        token = token.Trim();\n        double a;\n        if (token.EndsWith('%'))\n        {\n            if (!double.TryParse(token[..^1], NumberStyles.Float, CultureInfo.InvariantCulture, out var pct)\n                || pct < 0 || pct > 100)\n                throw new ArgumentException($\"Invalid color value: '{original}'. Alpha percentage must be 0%-100%.\");\n            a = pct / 100.0;\n        }\n        else\n        {\n            if (!double.TryParse(token, NumberStyles.Float, CultureInfo.InvariantCulture, out a) || a < 0 || a > 1)\n                throw new ArgumentException($\"Invalid color value: '{original}'. Alpha must be 0-1 (e.g. 0.5) or 0%-100%.\");\n        }\n        return (byte)Math.Round(a * 255.0);\n    }\n\n    private static double ParseHueDegrees(string token, string original)\n    {\n        token = token.Trim();\n        // Strip an optional `deg` suffix (CSS allows it; other angle units\n        // — turn/rad/grad — are out of scope for the input vocabulary we care\n        // about and would just need their own multipliers if asked for).\n        if (token.EndsWith(\"deg\", StringComparison.OrdinalIgnoreCase))\n            token = token[..^3].Trim();\n        if (!double.TryParse(token, NumberStyles.Float, CultureInfo.InvariantCulture, out var h))\n            throw new ArgumentException($\"Invalid color value: '{original}'. Hue must be a number in degrees.\");\n        h %= 360;\n        if (h < 0) h += 360;\n        return h;\n    }","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/ParseHelpers.cs#L168-L204","documentation":"Thrown by ParseAlphaComponent when alpha is a bare decimal (no %) that does not parse or is outside the 0-1 range. Alpha as a fraction must be in [0,1]; values like 1.5 or -0.2 are rejected. If you want to express 50%, either write 0.5 or 50%.","triggerScenarios":"Passing rgba(0,0,0,1.5), rgba(0,0,0,50) (mistaking the fraction field for a percentage), or rgba(0,0,0,-0.1).","commonSituations":"Treating the alpha slot as a 0-100 percentage by habit; opacity computed as a ratio that can exceed 1; passing a raw integer from a 0-255 alpha texture.","solutions":["Express alpha as a fraction in [0,1] (e.g. 0.5).","If your value is a percentage, append % (50%) instead of dividing nothing.","Clamp the fraction: alpha = Math.Clamp(alpha, 0.0, 1.0)."],"exampleFix":"// before\nvar c = $\"rgba(0,0,0,{opacity})\"); // opacity == 1.5\nParseColor(c); // throws 287\n\n// after\nvar c = $\"rgba(0,0,0,{Math.Clamp(opacity,0.0,1.0)})\");\nParseColor(c);","handlingStrategy":"validation","validationCode":"var a = Math.Clamp(opacity, 0.0, 1.0);\n// build: $\"rgba(0,0,0,{a})\"","typeGuard":"static bool IsValidAlphaFraction(string token)\n    => double.TryParse(token, CultureInfo.InvariantCulture, out var v) && v >= 0 && v <= 1;","tryCatchPattern":"try { color = ParseColor(spec); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Alpha must be 0-1\"))\n{ spec = \"rgba(0,0,0,1)\"; }","preventionTips":["Keep alpha as a [0,1] fraction or a [0,100]% — never 0-100 bare.","Clamp fractions before formatting.","Document which form each color field expects."],"tags":["color","validation","argument","alpha","range"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}