{"record":{"id":"59e524fd5e8d81d6","repo":"SubtitleEdit/subtitleedit","slug":"invalid-hex-string-59e524","errorCode":null,"errorMessage":"Invalid hex string.","messagePattern":"Invalid hex string\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/ui/Logic/SkColorExtensions.cs","lineNumber":33,"sourceCode":"    {\n        return includeAlpha\n            ? $\"#{color.Alpha:X2}{color.Red:X2}{color.Green:X2}{color.Blue:X2}\" // ARGB\n            : $\"#{color.Red:X2}{color.Green:X2}{color.Blue:X2}\";               // RGB\n    }\n\n    public static Color ToAvaloniaColor(this SKColor color)\n    {\n        return new Color(color.Alpha, color.Red, color.Green, color.Blue);\n    }\n\n    /// <summary>\n    /// Converts a hex string (e.g., \"#RRGGBB\" or \"#AARRGGBB\") to an SKColor.\n    /// </summary>\n    public static SKColor FromHex(this string hex)\n    {\n        if (string.IsNullOrWhiteSpace(hex))\n        {\n            throw new ArgumentException(\"Invalid hex string.\");\n        }\n\n        hex = hex.TrimStart('#');\n\n        byte a = 255, r, g, b;\n\n        if (hex.Length == 6)\n        {\n            // Format: RRGGBB\n            r = byte.Parse(hex.Substring(0, 2), NumberStyles.HexNumber);\n            g = byte.Parse(hex.Substring(2, 2), NumberStyles.HexNumber);\n            b = byte.Parse(hex.Substring(4, 2), NumberStyles.HexNumber);\n        }\n        else if (hex.Length == 8)\n        {\n            // Format: AARRGGBB\n            a = byte.Parse(hex.Substring(0, 2), NumberStyles.HexNumber);\n            r = byte.Parse(hex.Substring(2, 2), NumberStyles.HexNumber);","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/ui/Logic/SkColorExtensions.cs#L15-L51","documentation":"ArgumentException from FromHex when the input is null, empty, or whitespace-only. The hex parser requires a non-empty string before it can strip '#' and parse channels.","triggerScenarios":"A color setting was never assigned (null), an empty config value, or whitespace-only input passed to FromHex.","commonSituations":"Default config before the user picks a color, a config migration that dropped a value, or a theme with a missing color key.","solutions":["Seed the color setting with a sensible default hex at the configuration source.","Guard callers with !string.IsNullOrWhiteSpace(hex) before calling FromHex.","Treat a missing value as a known default (e.g. transparent or white) rather than propagating the exception."],"exampleFix":"// before\nvar color = setting.FromHex();\n\n// after\nvar color = string.IsNullOrWhiteSpace(setting) ? SKColors.White : setting.FromHex();","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(setting)) setting = \"#FFFFFFFF\";\nvar color = setting.FromHex();","typeGuard":null,"tryCatchPattern":"SKColor color;\ntry { color = setting.FromHex(); }\ncatch (ArgumentException) { color = SKColors.White; logger.LogWarning(\"Empty color value, using default\"); }","preventionTips":["Seed every color setting with a default hex at the config source.","Guard callers with IsNullOrWhiteSpace before FromHex.","Validate color values during config migration."],"tags":["color","parsing","validation","configuration"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}