iOfficeAI/OfficeCLI · error · ArgumentException
'import' command requires 'text' field with the CSV/TSV cont
Error message
'import' command requires 'text' field with the CSV/TSV content.
What it means
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.
Source
Thrown at src/officecli/CommandBuilder.cs:1116
}
return addMsg;
}
}
case "import":
{
// CSV/TSV bulk import — batch counterpart of the standalone
// `officecli import` command (CommandBuilder.Import.cs). The
// CSV content rides the item's `text` field; `parent` is the
// sheet path. This is the value-baseline carrier for
// `dump --format batch` on .xlsx (ExcelBatchEmitter).
if (handler is not OfficeCli.Handlers.ExcelHandler importXl)
throw new CliException("'import' batch command is only supported for .xlsx files")
{ Code = "unsupported_type" };
var importParent = item.Parent ?? item.Path;
if (string.IsNullOrEmpty(importParent))
throw new ArgumentException("'import' command requires 'parent' field (sheet path). Example: {\"command\": \"import\", \"parent\": \"/Sheet1\", \"text\": \"a,b\\n1,2\"}");
if (item.Text == null)
throw new ArgumentException("'import' command requires 'text' field with the CSV/TSV content.");
// CONSISTENCY(import-vocabulary): props mirror the standalone
// command's options — format=csv|tsv, header, start-cell.
char importDelim = ',';
if (props.TryGetValue("format", out var importFmt) && !string.IsNullOrEmpty(importFmt))
{
importDelim = importFmt.ToLowerInvariant() switch
{
"tsv" => '\t',
"csv" => ',',
_ => throw new CliException($"Unknown format: {importFmt}. Use 'csv' or 'tsv'")
{ Code = "invalid_value", ValidValues = ["csv", "tsv"] },
};
}
var importHeader = props.TryGetValue("header", out var importHdr)
&& OfficeCli.Core.ParseHelpers.IsTruthy(importHdr);
var importStart = props.TryGetValue("start-cell", out var importSc) && !string.IsNullOrEmpty(importSc)
? importSc
: props.TryGetValue("startcell", out var importSc2) && !string.IsNullOrEmpty(importSc2)View on GitHub (pinned to 1ced45e900)
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").
Example fix
// before
{"command":"import","parent":"/Sheet1"}
// after
{"command":"import","parent":"/Sheet1","text":"a,b\n1,2"} Defensive patterns
Strategy: validation
Validate before calling
// Note: only null is rejected here — empty string "" is accepted.
if (item.Text == null)
throw new ArgumentException("'import' requires a non-null 'text' field");
// if an empty import is unintended, also guard empty:
if ((item.Text ?? "").Length == 0) throw new ArgumentException("'import' text is empty"); Type guard
static bool IsValidImportItem(BatchItem i)
=> !string.IsNullOrEmpty(i.Parent ?? i.Path) && i.Text != null; Prevention
- 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'.
When it happens
Trigger: {"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".
Common situations: 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.
Related errors
- unsupported_type
- 'import' command requires 'parent' field (sheet path). Examp
- invalid_input
- Path not found: {path}
- 'query' command requires 'selector' field. Example: {"comman
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/05092b479e510feb.
Report an issue: GitHub.