{"record":{"id":"541a069733695225","repo":"File-New-Project/EarTrumpet","slug":"brushvalueparser-error-value-element","errorCode":null,"errorMessage":"BrushValueParser Error: '{value}' {element}","messagePattern":"BrushValueParser Error: '(.+?)' (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"EarTrumpet/UI/Themes/BrushValueParser.cs","lineNumber":172,"sourceCode":"                        // But it will succeed when the element Loaded is called.\r\n                        ret = Colors.HotPink;\r\n                        Trace.WriteLine($\"## BrushValueParser Parse FAILED ## '{value}' {element}\");\r\n                    }\r\n                }\r\n                else\r\n                {\r\n                    ret = color;\r\n                }\r\n\r\n                if (opacity > 0)\r\n                {\r\n                    ret.A = (byte)(opacity * 255);\r\n                }\r\n                return new SolidColorBrush(ret);\r\n            }\r\n            catch (Exception ex)\r\n            {\r\n                throw new Exception($\"BrushValueParser Error: '{value}' {element}\", ex);\r\n            }\r\n        }\r\n\r\n        private static bool FindReference(DependencyObject element, string searchKey, out SolidColorBrush outRef)\r\n        {\r\n            bool isLight = Options.GetSource(element) == Options.SourceKind.App ? SystemSettings.IsLightTheme : SystemSettings.IsSystemLightTheme;\r\n            var reference = Manager.Current.References.FirstOrDefault(r => r.Key == searchKey.Split('/')[0]);\r\n            if (reference != null)\r\n            {\r\n                if (reference.Value != null)\r\n                {\r\n                    outRef = Parse(element, reference.Value);\r\n                    return true;\r\n                }\r\n                else\r\n                {\r\n                    var tab = new Dictionary<Rule.Kind, bool>();\r\n                    tab.Add(Rule.Kind.Any, true);\r","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/File-New-Project/EarTrumpet/blob/aa894e51c22f5f9a939b31b224c4d2d3e163416e/EarTrumpet/UI/Themes/BrushValueParser.cs#L154-L190","documentation":"The entire body of BrushValueParser.Parse is wrapped in try/catch that rethrows every failure as a new Exception(\"BrushValueParser Error: ...\", ex). The real cause is in InnerException — typically one of the inner NotImplementedException throws (unknown theme key, rule-not-found, bad slashes) or a FormatException from color parsing. The wrapper preserves the offending value and element for diagnostics.","triggerScenarios":"Any unhandled failure inside Parse: an unknown color name that is not a hex color, Immersive color, Colors/SystemColors property, nor a resolvable reference; a malformed opacity segment; a Reference whose rules do not match; the HighContrast/Dark/Light fallthroughs.","commonSituations":"Typo in a theme brush string; reference to an undefined Manager key; color name not present on the running Windows build (Immersive color missing); malformed \"Color/0.5/0.2\" opacity.","solutions":["Read ex.InnerException to find the true failure (one of errors 7, 8, 10, 11 or a FormatException) and fix that specific cause.","Validate the theme value string against the supported grammar (scope:key=value pairs, optional /opacity, known color names) before passing to Parse.","Ensure any referenced Manager.References key is defined.","Test with the target Windows build so Immersive color names resolve."],"exampleFix":"// before: value = \"Bacground=#FF0000\"   // typo, not a known color -> wrapped error\n// after:  value = \"Background=#FF0000\"\n// diagnostic: catch (Exception ex) { var root = ex.InnerException ?? ex; Trace.WriteLine(root.Message); }","handlingStrategy":"try-catch","validationCode":"// optional: validate grammar before Parse\nstatic bool IsValidMarkup(string v)\n{\n    if (string.IsNullOrWhiteSpace(v)) return false;\n    foreach (var seg in v.Split(','))\n        foreach (var part in seg.Split('/'))\n            if (part.IndexOf('=') < 0 && part.Length == 0) return false;\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try { return BrushValueParser.Parse(element, value); }\ncatch (Exception ex)\n{\n    var root = ex.InnerException ?? ex;\n    Trace.WriteLine($\"BrushValueParser failed for '{value}': {root.Message}\");\n    return new SolidColorBrush(Colors.HotPink); // mirror the in-parser fallback\n}","preventionTips":["Always inspect InnerException — the wrapper hides the real cause.","Lint theme markup in CI for known color names and valid opacity segments.","Confirm referenced Manager keys exist and Immersive colors exist on the target OS build."],"tags":["theme","brush","wpf","error-wrapper","diagnostics","eartrumpet-ui"],"backgroundTag":null,"analyzedSha":"aa894e51c22f5f9a939b31b224c4d2d3e163416e","analyzedAt":"2026-08-13T18:51:30.564Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}