iOfficeAI/OfficeCLI · error · ArgumentException

'import' command requires 'parent' field (sheet path). Examp

Error message

'import' command requires 'parent' field (sheet path). Example: {"command": "import", "parent": "/Sheet1", "text": "a,b\n1,2"}

What it means

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.

Source

Thrown at src/officecli/CommandBuilder.cs:1114

                        }
                        if (hint != null) addMsg += "\nWARNING: " + hint;
                    }
                    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)

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Add a parent sheet path: {"command":"import","parent":"/Sheet1","text":"a,b\n1,2"}.
  2. Provide "path" as the fallback if parent is unset.
  3. Ensure the sheet exists in the workbook before importing.
  4. Validate every import step has a non-empty parent (or path) before submission.

Example fix

// before
{"command":"import","text":"a,b\n1,2"}
// after
{"command":"import","parent":"/Sheet1","text":"a,b\n1,2"}
Defensive patterns

Strategy: validation

Validate before calling

var parent = item.Parent ?? item.Path;
if (string.IsNullOrEmpty(parent))
    throw new ArgumentException("'import' requires a non-empty 'parent' (sheet path)");

Type guard

static bool IsValidImportItem(BatchItem i)
    => !string.IsNullOrEmpty(i.Parent ?? i.Path) && i.Text != null;

Prevention

When it happens

Trigger: {"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.

Common situations: 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.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/780621e8e8af8ce0. Report an issue: GitHub.