{"record":{"id":"a19478e28192399a","repo":"iOfficeAI/OfficeCLI","slug":"invalid-width-value-value-expected-a-finit","errorCode":null,"errorMessage":"Invalid 'width' value: '{value}'. Expected a finite number (column width in char units, e.g. 8.43).","messagePattern":"Invalid 'width' value: '(.+?)'\\. Expected a finite number \\(column width in char units, e\\.g\\. 8\\.43\\)\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.cs","lineNumber":176,"sourceCode":"        return pts;\n    }\n\n    // CONSISTENCY(rc-units): Column width is in \"maximum digit width\" char\n    // units (Calibri 11pt ≈ 7px per char). Accepts bare number (char units,\n    // legacy) or unit-qualified px/cm/in/pt — physical sizes converted via\n    // the 7-px-per-char approximation Excel uses internally.\n    internal static double ParseColWidthChars(string value)\n    {\n        if (string.IsNullOrWhiteSpace(value))\n            throw new ArgumentException(\"Column width cannot be empty.\");\n        var trimmed = value.Trim();\n        double chars;\n        if (double.TryParse(trimmed, System.Globalization.NumberStyles.Float,\n                System.Globalization.CultureInfo.InvariantCulture, out var bare)\n            && !char.IsLetter(trimmed[^1]))\n        {\n            if (double.IsNaN(bare) || double.IsInfinity(bare))\n                throw new ArgumentException($\"Invalid 'width' value: '{value}'. Expected a finite number (column width in char units, e.g. 8.43).\");\n            chars = bare;\n        }\n        else\n        {\n            try\n            {\n                var emu = OfficeCli.Core.EmuConverter.ParseEmu(trimmed);\n                // 9525 EMU = 1 px; 7 px ≈ 1 char unit (Calibri 11pt MDW baseline)\n                var px = emu / EmuConverter.EmuPerPxF;\n                chars = px / 7.0;\n            }\n            catch (Exception ex)\n            {\n                throw new ArgumentException($\"Invalid 'width' value: '{value}'. Expected a finite number or unit-qualified value (e.g. 8.43, 20px, 2cm, 1in, 60pt).\", ex);\n            }\n        }\n        // DEFERRED(xlsx/row-height-validation) RC2: Excel column width is bounded\n        // [0, 255] character units. Validate at Set time.","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.cs#L158-L194","documentation":"Thrown by ParseColWidthChars when the bare-number branch parsed successfully but the value is NaN or Infinity. NumberStyles.Float accepts 'NaN'/'Infinity', so this guard rejects those sentinel strings before they would corrupt a column width.","triggerScenarios":"Passing width=NaN, width=Infinity, width=-Infinity, or any non-finite value the parser accepts.","commonSituations":"Upstream divide-by-zero producing NaN that is then interpolated into the prop; an LLM placeholder; serialization of a default(double) field.","solutions":["Replace the non-finite value with a finite number (column width is in character units, e.g. 8.43).","Fix the upstream arithmetic that produced NaN/Infinity.","Validate with double.IsFinite before constructing the prop value."],"exampleFix":"// before\nvar w = ratio * base;     // ratio = 0/0 -> NaN\nset($\"/Sheet1/col[B] --prop width={w}\");\n\n// after\nvar w = double.IsFinite(ratio) ? ratio * base : 8.43;\nset($\"/Sheet1/col[B] --prop width={w}\");","handlingStrategy":"validation","validationCode":"if (!double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out var d) || !double.IsFinite(d))\n    throw new ArgumentException($\"Column width must be a finite number, got '{value}'.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reject NaN/Infinity at the source.","Use double.IsFinite as the canonical finite check."],"tags":["excel","validation","column-width","numeric"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}