{"record":{"id":"92f67a6eec02db57","repo":"HandyOrg/HandyControl","slug":"invalidstringcollayout","errorCode":null,"errorMessage":"InvalidStringColLayout","messagePattern":"InvalidStringColLayout","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Avalonia/HandyControl_Avalonia/Tools/Extension/ColLayout.cs","lineNumber":104,"sourceCode":"                }\n                return ColLayoutStatus.Sm;\n            }\n            return ColLayoutStatus.Md;\n        }\n        if (width < XlMaxWidth)\n        {\n            if (width < LgMaxWidth)\n            {\n                return ColLayoutStatus.Lg;\n            }\n            return ColLayoutStatus.Xl;\n        }\n        return ColLayoutStatus.Xxl;\n    }\n\n    public static ColLayout Parse(string s)\n    {\n        if (string.IsNullOrWhiteSpace(s)) throw new FormatException(\"InvalidStringColLayout\");\n\n        var separators = new[] { ',', ' ' };\n        var tokens = s.Split(separators, StringSplitOptions.RemoveEmptyEntries);\n        var lengths = new int[6];\n        var i = 0;\n        foreach (var token in tokens)\n        {\n            if (i >= 6) throw new FormatException(\"InvalidStringColLayout\");\n            lengths[i++] = int.Parse(token, CultureInfo.InvariantCulture);\n        }\n\n        return i switch\n        {\n            1 => new ColLayout(lengths[0]),\n            2 => new ColLayout { Xs = lengths[0], Sm = lengths[1] },\n            3 => new ColLayout { Xs = lengths[0], Sm = lengths[1], Md = lengths[2] },\n            4 => new ColLayout { Xs = lengths[0], Sm = lengths[1], Md = lengths[2], Lg = lengths[3] },\n            5 => new ColLayout","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Avalonia/HandyControl_Avalonia/Tools/Extension/ColLayout.cs#L86-L122","documentation":"ColLayout.Parse throws FormatException('InvalidStringColLayout') when the input string is null, empty or whitespace, because no column lengths can be extracted from it. Parse is the inverse of ColLayout.ToString and is meant for strings like '24,12,8,4,2,1'.","triggerScenarios":"Passing null, \"\", or whitespace-only strings to ColLayout.Parse, typically from XAML attributes or config values that were never set.","commonSituations":"Binding a grid definition from app settings or a database field that is empty; XAML where the ColLayout attribute was left blank; deserialization of incomplete config.","solutions":["Ensure the string is non-empty before calling ColLayout.Parse","Provide a default layout when the source string is blank, e.g. string.IsNullOrEmpty(s) ? ColLayout.Default : ColLayout.Parse(s)","Catch FormatException around Parse and fall back to a default layout"],"exampleFix":"// before\nvar layout = ColLayout.Parse(settings.ColLayout); // throws when empty\n// after\nvar layout = string.IsNullOrWhiteSpace(settings.ColLayout) ? ColLayout.Default : ColLayout.Parse(settings.ColLayout);","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrWhiteSpace(s)) { var layout = ColLayout.Parse(s); }","typeGuard":"static bool IsValidColLayoutString(string? s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":"try { return ColLayout.Parse(s); }\ncatch (FormatException) { return ColLayout.Default; }","preventionTips":["Validate input strings before parsing","Default empty config values to ColLayout.Default","Use ColLayout objects in code instead of round-tripping strings"],"tags":["format","parsing","col-layout"],"backgroundTag":"empty-required-field","analyzedSha":"2c0875ebd67326e0c67282967e3e809c69282fee","analyzedAt":"2026-09-14T14:45:29.754Z","contentChangedAt":"2026-09-14T14:45:29.754Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}