{"record":{"id":"05092b479e510feb","repo":"iOfficeAI/OfficeCLI","slug":"import-command-requires-text-field-with-the-cs","errorCode":null,"errorMessage":"'import' command requires 'text' field with the CSV/TSV content.","messagePattern":"'import' command requires 'text' field with the CSV/TSV content\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/CommandBuilder.cs","lineNumber":1116,"sourceCode":"                    }\n                    return addMsg;\n                }\n            }\n            case \"import\":\n            {\n                // CSV/TSV bulk import — batch counterpart of the standalone\n                // `officecli import` command (CommandBuilder.Import.cs). The\n                // CSV content rides the item's `text` field; `parent` is the\n                // sheet path. This is the value-baseline carrier for\n                // `dump --format batch` on .xlsx (ExcelBatchEmitter).\n                if (handler is not OfficeCli.Handlers.ExcelHandler importXl)\n                    throw new CliException(\"'import' batch command is only supported for .xlsx files\")\n                        { Code = \"unsupported_type\" };\n                var importParent = item.Parent ?? item.Path;\n                if (string.IsNullOrEmpty(importParent))\n                    throw new ArgumentException(\"'import' command requires 'parent' field (sheet path). Example: {\\\"command\\\": \\\"import\\\", \\\"parent\\\": \\\"/Sheet1\\\", \\\"text\\\": \\\"a,b\\\\n1,2\\\"}\");\n                if (item.Text == null)\n                    throw new ArgumentException(\"'import' command requires 'text' field with the CSV/TSV content.\");\n                // CONSISTENCY(import-vocabulary): props mirror the standalone\n                // command's options — format=csv|tsv, header, start-cell.\n                char importDelim = ',';\n                if (props.TryGetValue(\"format\", out var importFmt) && !string.IsNullOrEmpty(importFmt))\n                {\n                    importDelim = importFmt.ToLowerInvariant() switch\n                    {\n                        \"tsv\" => '\\t',\n                        \"csv\" => ',',\n                        _ => throw new CliException($\"Unknown format: {importFmt}. Use 'csv' or 'tsv'\")\n                            { Code = \"invalid_value\", ValidValues = [\"csv\", \"tsv\"] },\n                    };\n                }\n                var importHeader = props.TryGetValue(\"header\", out var importHdr)\n                    && OfficeCli.Core.ParseHelpers.IsTruthy(importHdr);\n                var importStart = props.TryGetValue(\"start-cell\", out var importSc) && !string.IsNullOrEmpty(importSc)\n                    ? importSc\n                    : props.TryGetValue(\"startcell\", out var importSc2) && !string.IsNullOrEmpty(importSc2)","sourceCodeStart":1098,"sourceCodeEnd":1134,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/CommandBuilder.cs#L1098-L1134","documentation":"Thrown by ExecuteBatchItem for a batch \"import\" step that has a parent but a null \"text\" field. The CSV/TSV payload rides the text field. Note this check is `item.Text == null`, so an EMPTY string (\"\") does NOT trigger it — only a missing text field does. This is a deliberate asymmetry from the parent/path checks which use IsNullOrEmpty.","triggerScenarios":"{\"command\":\"import\",\"parent\":\"/Sheet1\"} (no text); an import step where the text field was omitted; a generator whose CSV source returned null; a field misspelled as \"txt\".","commonSituations":"Forgotten text field; a CSV read that returned null on error; field misspelling; conditional logic that left text unset; an LLM-generated batch that omitted the payload.","solutions":["Add the text field with the CSV/TSV content: {\"command\":\"import\",\"parent\":\"/Sheet1\",\"text\":\"a,b\\n1,2\"}.","Ensure the CSV source produces a non-null string (coalesce null to \"\" if an empty import is intended).","Validate every import step has a non-null text field before submission.","Check for misspelled field names (must be exactly \"text\")."],"exampleFix":"// before\n{\"command\":\"import\",\"parent\":\"/Sheet1\"}\n// after\n{\"command\":\"import\",\"parent\":\"/Sheet1\",\"text\":\"a,b\\n1,2\"}","handlingStrategy":"validation","validationCode":"// Note: only null is rejected here — empty string \"\" is accepted.\nif (item.Text == null)\n    throw new ArgumentException(\"'import' requires a non-null 'text' field\");\n// if an empty import is unintended, also guard empty:\nif ((item.Text ?? \"\").Length == 0) throw new ArgumentException(\"'import' text is empty\");","typeGuard":"static bool IsValidImportItem(BatchItem i)\n    => !string.IsNullOrEmpty(i.Parent ?? i.Path) && i.Text != null;","tryCatchPattern":null,"preventionTips":["Remember the asymmetry: null text throws, empty text does not — guard both if needed.","Coalesce a null CSV source to \"\" only if an empty import is intentional.","Ensure the field is spelled exactly 'text'."],"tags":["batch","import","validation","officecli"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}