{"record":{"id":"269b4875d653024d","repo":"iOfficeAI/OfficeCLI","slug":"pivot-name-must-not-be-empty","errorCode":null,"errorMessage":"pivot name must not be empty","messagePattern":"pivot name must not be empty","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/PivotTableHelper.cs","lineNumber":177,"sourceCode":"        if (string.IsNullOrEmpty(key)) return key;\n        var lower = key.ToLowerInvariant();\n        return _pivotKeyAliases.TryGetValue(lower, out var canonical) ? canonical : lower;\n    }\n\n    /// <summary>\n    /// Validate a user-supplied pivot table name and return the trimmed value.\n    /// Throws ArgumentException for empty, whitespace-only, control-character,\n    /// or over-255-character names. Does NOT check workbook-level uniqueness\n    /// (that is the caller's responsibility).\n    /// R16-2: extracted from CreatePivotTable so SetPivotTableProperties can\n    /// reuse the same validation — previously Set accepted empty/whitespace\n    /// names without any check.\n    /// </summary>\n    private static string ValidatePivotName(string name)\n    {\n        // Empty string is rejected — a blank name is always an error.\n        if (string.IsNullOrEmpty(name))\n            throw new ArgumentException(\"pivot name must not be empty\");\n        var trimmed = name.Trim();\n        // Whitespace-only names are rejected — R8-4.\n        if (trimmed.Length == 0)\n            throw new ArgumentException(\"pivot name must not be whitespace-only\");\n        // ASCII control characters are rejected — R8-5.\n        foreach (var ch in trimmed)\n        {\n            if (ch < 0x20 || ch == 0x7F)\n                throw new ArgumentException(\"pivot name contains invalid control characters\");\n        }\n        // 255-character limit — R11-4.\n        if (trimmed.Length > 255)\n            throw new ArgumentException(\"pivot name exceeds 255-character limit\");\n        return trimmed;\n    }\n\n    /// <summary>\n    /// Canonical key set recognized by the pivot Add / Set pipeline. Any","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/PivotTableHelper.cs#L159-L195","documentation":"Thrown by ValidatePivotName when the supplied pivot name is null or an empty string. Every pivot table in OOXML requires a non-empty Name attribute. This validation is shared between CreatePivotTable (Add) and SetPivotTableProperties (Set name=) so both paths enforce the same rule (R16-2 extracted it for reuse after Set previously accepted empty names unchecked).","triggerScenarios":"Calling Add pivot name='' or Set pivot name='' with an empty string. Or passing a null/empty name property through the properties dictionary.","commonSituations":"Forgetting to include name= in an Add call when the pipeline requires it; programmatic generation that passes an empty string when a name field was blank in a config; passing name= with no value.","solutions":["Provide a non-empty, non-whitespace name for the pivot table.","If generating names programmatically, default to a derived name when the input is empty.","Validate the name field in your own code before calling Add or Set."],"exampleFix":"// before\nAdd pivot source=Sheet1!A1:D10 name=''\n// after\nAdd pivot source=Sheet1!A1:D10 name='SalesPivot'","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(pivotName))\n    throw new ArgumentException(\"Pivot name must not be empty.\");","typeGuard":"static bool IsValidPivotName(string name) => !string.IsNullOrEmpty(name) && name.Trim().Length > 0;","tryCatchPattern":null,"preventionTips":["Always supply a non-empty name when creating or renaming a pivot.","Validate the name field in your input layer before passing it to the API.","Use a sensible default name if the user input is empty."],"tags":["pivot","excel","naming","validation","input-validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}