{"record":{"id":"c4754fab613dd5dc","repo":"iOfficeAI/OfficeCLI","slug":"unknown-action-action-supported-append-prepe","errorCode":null,"errorMessage":"Unknown action: {action}. Supported: append, prepend, insertbefore, insertafter, replace, remove, setattr","messagePattern":"Unknown action: (.+?)\\. Supported: append, prepend, insertbefore, insertafter, replace, remove, setattr","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/RawXmlHelper.cs","lineNumber":141,"sourceCode":"        // never masked by a no-match xpath. Without this, a typo'd action\n        // combined with a stale xpath would batch-report \"OK\" while doing\n        // nothing — the user sees no signal that the action name was wrong.\n        var normalizedAction = action.ToLowerInvariant();\n        switch (normalizedAction)\n        {\n            case \"append\":\n            case \"prepend\":\n            case \"insertbefore\":\n            case \"before\":\n            case \"insertafter\":\n            case \"after\":\n            case \"replace\":\n            case \"remove\":\n            case \"delete\":\n            case \"setattr\":\n                break;\n            default:\n                throw new ArgumentException($\"Unknown action: {action}. Supported: append, prepend, insertbefore, insertafter, replace, remove, setattr\");\n        }\n\n        var nodes = xDoc.XPathSelectElements(xpath, nsManager).ToList();\n        if (nodes.Count == 0)\n        {\n            // Throw rather than return 0 affected with a stderr nudge: the\n            // stderr line is trivially dropped by pipelines and batch\n            // envelopes, leaving callers with success:true on a no-op. A\n            // typo'd xpath then looks indistinguishable from a real\n            // mutation. Surface the failure where every consumer\n            // (standalone, batch, resident) already handles exceptions.\n            throw new ArgumentException(\n                $\"raw-set: XPath matched no elements: {xpath}. \" +\n                \"Hint: auto-registered namespace prefixes: \" +\n                string.Join(\", \", CommonNamespaces.Keys.Order()) +\n                \". No xmlns declarations needed in --xml fragments.\");\n        }\n","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/RawXmlHelper.cs#L123-L159","documentation":"Thrown by RawXmlHelper.ExecuteOnXmlString when the action argument is not one of the supported verbs: append, prepend, insertbefore (alias: before), insertafter (alias: after), replace, remove (alias: delete), setattr. Validation runs BEFORE the XPath is evaluated, so a bad action is never masked by a no-match XPath. Note: aliases 'before', 'after', 'delete' are accepted but not listed in the error message's 'Supported:' text.","triggerScenarios":"RawXmlHelper.Execute(rootElement, xpath, action, xml) or RawXmlHelper.Execute(part, xpath, action, xml) is called with an action string that doesn't match any case in the normalization switch. The comparison is case-insensitive (action.ToLowerInvariant()).","commonSituations":"Typo: 'inserBefore', 'apend', 'setatr'. Using a synonym not in the list: 'add', 'insert', 'modify', 'update', 'change', 'delete_all'. Passing a command name from a different API surface. Accidentally passing the XPath as the action argument (argument order swap).","solutions":["Use one of the exact action names: append, prepend, insertbefore, insertafter, replace, remove, setattr (case-insensitive). Aliases before/after/delete also work.","Check argument order: Execute(rootElement, xpath, action, xml) — a positional swap of xpath and action produces this error.","For adding content, use 'append' (inside target as last child) or 'insertafter' (after target as sibling).","For removing, use 'remove' or 'delete' (alias). For attribute changes, use 'setattr' with name=value syntax."],"exampleFix":"// before: typo or wrong synonym\nRawXmlHelper.Execute(root, xpath, \"insert\", \"<w:p/>\");\nRawXmlHelper.Execute(root, xpath, \"add\", \"<w:p/>\");\n\n// after: correct action name\nRawXmlHelper.Execute(root, xpath, \"insertafter\", \"<w:p/>\");\nRawXmlHelper.Execute(root, xpath, \"append\", \"<w:p/>\");","handlingStrategy":"validation","validationCode":"// Validate action before calling Execute\nstatic readonly HashSet<string> ValidActions = new()\n{\n    \"append\", \"prepend\", \"insertbefore\", \"before\",\n    \"insertafter\", \"after\", \"replace\", \"remove\", \"delete\", \"setattr\"\n};\n\nif (!ValidActions.Contains(action.ToLowerInvariant()))\n    throw new ArgumentException($\"Invalid action '{action}'. Supported: {string.Join(\", \", ValidActions)}\");\n\nRawXmlHelper.Execute(rootElement, xpath, action, xml);","typeGuard":"static bool IsValidAction(string action) =>\n    action.ToLowerInvariant() is \"append\" or \"prepend\" or \"insertbefore\" or \"before\"\n        or \"insertafter\" or \"after\" or \"replace\" or \"remove\" or \"delete\" or \"setattr\";","tryCatchPattern":"try\n{\n    RawXmlHelper.Execute(rootElement, xpath, action, xml);\n}\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Unknown action\"))\n{\n    Console.Error.WriteLine($\"'{action}' is not a valid raw-set action. Use: append, prepend, insertbefore, insertafter, replace, remove, setattr.\");\n}","preventionTips":["Validate the action against the known set before calling Execute.","Double-check argument order: Execute(root, xpath, action, xml) — swapping xpath and action triggers this.","Use constants or an enum for action names to prevent typos."],"tags":["xml","xpath","openxml","validation","argument"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}