{"record":{"id":"780621e8e8af8ce0","repo":"iOfficeAI/OfficeCLI","slug":"import-command-requires-parent-field-sheet-pa","errorCode":null,"errorMessage":"'import' command requires 'parent' field (sheet path). Example: {\"command\": \"import\", \"parent\": \"/Sheet1\", \"text\": \"a,b\\n1,2\"}","messagePattern":"'import' command requires 'parent' field \\(sheet path\\)\\. Example: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/CommandBuilder.cs","lineNumber":1114,"sourceCode":"                        }\n                        if (hint != null) addMsg += \"\\nWARNING: \" + hint;\n                    }\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)","sourceCodeStart":1096,"sourceCodeEnd":1132,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/CommandBuilder.cs#L1096-L1132","documentation":"Thrown by ExecuteBatchItem for a batch \"import\" step when both \"parent\" and \"path\" are null/empty. Import needs the target sheet path to know which sheet to write into; path is accepted as a fallback for parent.","triggerScenarios":"{\"command\":\"import\",\"text\":\"a,b\\n1,2\"} (no parent); an import step whose parent/path variables were both empty; a generator that emitted text but not the sheet path.","commonSituations":"Forgotten sheet path; a parent computed from a null/empty variable (e.g. missing sheet name); copy-paste that lost the parent field; templating that failed to interpolate the sheet name.","solutions":["Add a parent sheet path: {\"command\":\"import\",\"parent\":\"/Sheet1\",\"text\":\"a,b\\n1,2\"}.","Provide \"path\" as the fallback if parent is unset.","Ensure the sheet exists in the workbook before importing.","Validate every import step has a non-empty parent (or path) before submission."],"exampleFix":"// before\n{\"command\":\"import\",\"text\":\"a,b\\n1,2\"}\n// after\n{\"command\":\"import\",\"parent\":\"/Sheet1\",\"text\":\"a,b\\n1,2\"}","handlingStrategy":"validation","validationCode":"var parent = item.Parent ?? item.Path;\nif (string.IsNullOrEmpty(parent))\n    throw new ArgumentException(\"'import' requires a non-empty 'parent' (sheet path)\");","typeGuard":"static bool IsValidImportItem(BatchItem i)\n    => !string.IsNullOrEmpty(i.Parent ?? i.Path) && i.Text != null;","tryCatchPattern":null,"preventionTips":["Always set parent (or path) to the target sheet on import steps.","Confirm the sheet exists before importing.","Guard against null/empty sheet-name variables."],"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"}