{"record":{"id":"18a78550f571c4b6","repo":"iOfficeAI/OfficeCLI","slug":"missing-argument","errorCode":"missing_argument","errorMessage":"Either --type or --from must be specified.","messagePattern":"Either --type or --from must be specified\\.","errorType":"error_code","errorClass":"CliException","httpStatus":null,"severity":"error","filePath":"src/officecli/CommandBuilder.Add.cs","lineNumber":127,"sourceCode":"                else\n                {\n                    foreach (var kv in unmatchedKvWarnings)\n                        Console.Error.WriteLine($\"WARNING: Bare property '{kv}' ignored. Did you mean: --prop {kv}\");\n                    Console.Error.WriteLine(\"Hint: Properties must be passed with --prop flag, e.g. officecli add <file> <parent> --type picture --prop src=image.png\");\n                }\n            }\n\n            // TreatUnmatchedTokensAsErrors=false exists so the bare key=value\n            // warnings above can fire — but it also let a completely unknown\n            // `--flag value` pair (e.g. `--at A2`) vanish silently with exit 0,\n            // placing the element somewhere the caller did not intend. Any\n            // remaining unmatched --option that DetectUnmatchedKeyValues did\n            // not claim is a hard error, matching set/get behavior.\n            RejectUnknownOptionTokens(result, unmatchedKvWarnings);\n\n            if (string.IsNullOrEmpty(type) && string.IsNullOrEmpty(from))\n            {\n                throw new OfficeCli.Core.CliException(\"Either --type or --from must be specified.\")\n                {\n                    Code = \"missing_argument\",\n                    Suggestion = \"Use --type to specify element type, or --from to copy an existing element.\",\n                    Help = \"officecli add <file> <parent> --type <type> --prop src=<file>\"\n                };\n            }\n\n            // BUG(add-from-prop-silently-ignored): --from copies an existing\n            // element verbatim and does not apply --prop overrides. Reject the\n            // combination explicitly so users don't think their --prop took\n            // effect. Workaround: copy first, then `set` the result path.\n            if (!string.IsNullOrEmpty(from) && props != null && props.Length > 0)\n            {\n                throw new OfficeCli.Core.CliException(\"--prop cannot be combined with --from; use `set` on the copied path to modify properties.\")\n                {\n                    Code = \"invalid_argument\",\n                    Suggestion = \"Run `add --from` first, then `set <new-path> --prop k=v` on the result.\"\n                };","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/CommandBuilder.Add.cs#L109-L145","documentation":"Thrown by the `add` command when neither --type nor --from is provided. add needs to know what to insert: --type declares a new element kind, --from copies an existing element. With both empty the command has nothing to do, so it fails fast with code `missing_argument` and a Help string.","triggerScenarios":"`officecli add file.docx /body` with no --type and no --from. The guard at line 125 checks both are null/empty and throws.","commonSituations":"User forgets the element type entirely; a script drops the --type flag due to an unset variable; an agent assumes a default type exists; the parent path was intended as the only argument but type is mandatory.","solutions":["Add --type with a supported element kind (paragraph, run, table, sheet, row, cell, slide, shape, picture, etc.).","Or use --from to copy an existing element path instead of declaring a type.","Check the add help: `officecli add --help` for the full --type list."],"exampleFix":"# before\nofficecli add file.docx /body\n\n# after\nofficecli add file.docx /body --type paragraph","handlingStrategy":"validation","validationCode":"// Require type or from before invoking add.\nif (string.IsNullOrEmpty(type) && string.IsNullOrEmpty(from))\n    throw new ArgumentException(\"add requires --type or --from\");","typeGuard":"// Type guard: add intent is well-defined only with one of these.\nstatic bool HasAddIntent(string? type, string? from) =>\n    !string.IsNullOrEmpty(type) || !string.IsNullOrEmpty(from);","tryCatchPattern":null,"preventionTips":["Make --type a required parameter in your wrapper when --from is not supplied.","Reject empty/whitespace type strings at the input boundary, not at the CLI."],"tags":["argument-validation","add","cli","missing-argument"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}