{"record":{"id":"1c30641a2d1c7648","repo":"d2phap/ImageGlass","slug":"channelsstr-is-not-a-valid-color-channel","errorCode":null,"errorMessage":"'{channelsStr}' is not a valid color channel.\n\n----------\n👉🏼 Method: IG_SetColorChannels","messagePattern":"'(.+?)' is not a valid color channel\\.\n\n----------\n👉🏼 Method: IG_SetColorChannels","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"source/ImageGlass.Lib/Common/ServiceProviders/AppAPIs/AppAPIProvider.cs","lineNumber":1595,"sourceCode":"    /// Sets the image loading order value.\n    /// </summary>\n    public static void IG_SetLoadingOrderType(ImageOrderType orderType)\n    {\n        if (orderType == Core.Config.ImageLoadingOrderType) return;\n\n        Core.Config.ImageLoadingOrderType = orderType;\n        IG_ReloadList();\n    }\n\n\n    /// <summary>\n    /// Sets the image color channels.\n    /// </summary>\n    public void IG_SetColorChannels(string? channelsStr)\n    {\n        if (!Enum.TryParse<ColorChannels>(channelsStr, out var channels))\n        {\n            throw new ArgumentException($\"\"\"\n                '{channelsStr}' is not a valid color channel.\n\n                ----------\n                👉🏼 Method: {nameof(IG_SetColorChannels)}\n                \"\"\",\n                nameof(channelsStr));\n        }\n\n        IG_SetColorChannels(channels);\n    }\n\n\n    /// <summary>\n    /// Sets the image color channels.\n    /// </summary>\n    public static void IG_SetColorChannels(ColorChannels channels)\n    {\n        if (Viewer.SourceKind == PhotoSource.None || Core.IsBusy) return;","sourceCodeStart":1577,"sourceCodeEnd":1613,"githubUrl":"https://github.com/d2phap/ImageGlass/blob/4a3c4feceffc5a8bb5e56ba836509634aaae47a9/source/ImageGlass.Lib/Common/ServiceProviders/AppAPIs/AppAPIProvider.cs#L1577-L1613","documentation":"Thrown by the string overload of IG_SetColorChannels when Enum.TryParse<ColorChannels>(channelsStr) fails. ColorChannels is a [Flags] enum; valid names are R, G, B, A, and the combined aliases RGB, RGBA, RA, GA, BA. Enum.TryParse accepts comma-separated flag combinations (e.g., 'R,G') case-insensitively. Any token not in the set fails the whole parse.","triggerScenarios":"Calling IG_SetColorChannels(string) with 'red'/'green'/'blue'/'alpha', 'rgb ' (trailing space inside a combined token), 'RG' (not a defined name; use 'R,G' or 'RGB'), or 'All'.","commonSituations":"User types color names instead of single-letter flags; config with a non-defined combination like 'RB'; trailing whitespace inside a comma list.","solutions":["Use single-letter flags (R, G, B, A), the defined combined names (RGB, RGBA, RA, GA, BA), or a comma-separated combination of single letters like 'R,G'.","Validate with Enum.TryParse<ColorChannels> upstream and call the typed overload.","Trim each token in a comma-separated list before parsing."],"exampleFix":"// before\napi.IG_SetColorChannels(userInput);\n\n// after\nif (Enum.TryParse<ColorChannels>(userInput?.Trim(), true, out var channels))\n{\n    api.IG_SetColorChannels(channels);\n}","handlingStrategy":"validation","validationCode":"if (!Enum.TryParse<ColorChannels>(channelsStr?.Trim(), true, out var channels))\n    throw new ArgumentException($\"Unknown color channel '{channelsStr}'.\");\napi.IG_SetColorChannels(channels);","typeGuard":"static bool IsValidColorChannels(string? s) => Enum.TryParse<ColorChannels>(s?.Trim(), true, out _);","tryCatchPattern":"try { api.IG_SetColorChannels(channelsStr); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(channelsStr))\n{ /* valid: R, G, B, A, RGB, RGBA, RA, GA, BA, or comma combos like 'R,G' */ }","preventionTips":["Use single-letter flags or the defined combined names; for custom combos use comma-separated single letters.","Trim each token in a comma-separated list before parsing.","Validate with Enum.TryParse<ColorChannels> before calling."],"tags":["app-api","color","argument-parsing","enum","flags"],"backgroundTag":null,"analyzedSha":"4a3c4feceffc5a8bb5e56ba836509634aaae47a9","analyzedAt":"2026-08-13T16:58:15.523Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}