iOfficeAI/OfficeCLI · error · CliException

unsupported_type

unsupported_type

Error message

'import' batch command is only supported for .xlsx files

What it means

Thrown by ExecuteBatchItem for a batch "import" step (CSV/TSV bulk import) when the active handler is not the ExcelHandler. Import is the value-baseline carrier for ExcelBatchEmitter and only makes sense for spreadsheets, so it is rejected for Word/PowerPoint. CliException Code="unsupported_type".

Solutions

  1. Only run import batch steps against .xlsx files.
  2. Skip import steps when the document is not Excel.
  3. Branch the batch emitter on file extension/handler type before producing import steps.
  4. For non-Excel files, use set/add instead of import to populate content.

Example fix

// before: import step run against report.docx
{"command":"import","parent":"/Sheet1","text":"a,b\n1,2"}
// after: run the same step only against data.xlsx
officecli batch data.xlsx items.json
Defensive patterns

Strategy: validation

Validate before calling

// Only emit import steps for Excel workbooks.
if (!path.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase))
    continue;   // skip import for non-Excel files

Type guard

static bool CanImport(IDocumentHandler h) => h is ExcelHandler;

Try / catch

try { ExecuteBatchItem(handler, item, json); }
catch (CliException ex) when (ex.Code == "unsupported_type")
{ /* skip import step for this non-Excel document */ }

Prevention

When it happens

Trigger: {"command":"import","parent":"/Sheet1","text":"a,b\n1,2"} run against a .docx or .pptx; a dump --format batch from an .xlsx replayed against a non-Excel file; a generic batch driver that always emits import steps.

Common situations: A reusable batch script applied to the wrong file type; cross-type dump/replay; a generator that does not branch on extension before emitting import.

Related errors


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

Appendix: source

Thrown at src/officecli/CommandBuilder.cs:1110

                        {
                            string? addScope = handler is OfficeCli.Handlers.ExcelHandler ? "excel"
                                : handler is OfficeCli.Handlers.PowerPointHandler ? "pptx" : null;
                            hint = FormatUnsupported(addUnsupported, addScope);
                        }
                        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"] },
                    };

View on GitHub (pinned to 1ced45e900)