iOfficeAI/OfficeCLI · error · CliException

unsupported_format

unsupported_format

Error message

dump currently supports .docx, .pptx and .xlsx (got {ext})

What it means

Thrown by the `dump` command when the target file's extension is not .docx, .pptx, or .xlsx. dump only serializes the three supported Office formats; the extension check at line 50-53 rejects others with code `unsupported_format` before attempting to open the file.

Source

Thrown at src/officecli/CommandBuilder.Dump.cs:52

        dumpCommand.Add(dumpPathArg);
        dumpCommand.Add(formatOpt);
        dumpCommand.Add(outOpt);
        dumpCommand.Add(jsonOption);

        dumpCommand.SetAction(result => { var json = result.GetValue(jsonOption); return SafeRun(() =>
        {
            var file = result.GetValue(dumpFileArg)!;
            var path = OfficeCli.Core.MsysPathHint.Restore(result.GetValue(dumpPathArg)) ?? "/";
            var format = (result.GetValue(formatOpt) ?? "batch").ToLowerInvariant();
            var outPath = result.GetValue(outOpt);

            if (format != "batch")
                throw new CliException($"Unsupported --format: {format}. Valid: batch")
                    { Code = "invalid_format", ValidValues = ["batch"] };

            var ext = Path.GetExtension(file.FullName).ToLowerInvariant();
            if (ext != ".docx" && ext != ".pptx" && ext != ".xlsx")
                throw new CliException($"dump currently supports .docx, .pptx and .xlsx (got {ext})")
                    { Code = "unsupported_format" };

            // CONSISTENCY(file-not-found): mirror the get/set/query format —
            // "File not found: <path>. Use 'officecli create <path>' to create a
            // blank document, or check the file extension.". Without this
            // early guard the dump path falls through to the SDK opener whose
            // raw '.NET Could not find file' message disagrees with every
            // other command and skips the actionable suggestion.
            if (!File.Exists(file.FullName))
                throw new CliException(
                    $"File not found: {file.FullName}. " +
                    $"Use 'officecli create {file.FullName}' to create a blank document, " +
                    $"or check the file extension.")
                    { Code = "file_not_found" };

            // BUG-DUMP-R6-01: route through the resident if one holds the file.
            // Without this, dump opens its own handler and collides with
            // the resident's lock ("file being used by another process").

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Convert or re-save the file as .docx/.pptx/.xlsx first.
  2. Point dump at a genuine OOXML file.
  3. For legacy .doc/.ppt, open in the Office app and Save As the modern format.

Example fix

# before
officecli dump file.doc /

# after
officecli dump file.docx /
Defensive patterns

Strategy: validation

Validate before calling

// Check extension before dump.
var ext = Path.GetExtension(file).ToLowerInvariant();
if (ext is not (".docx" or ".pptx" or ".xlsx"))
    throw new NotSupportedException($"dump unsupported extension {ext}");

Type guard

// Guard: extension is dumpable.
static bool IsDumpable(string path) =>
    Path.GetExtension(path).ToLowerInvariant() is ".docx" or ".pptx" or ".xlsx";

Prevention

When it happens

Trigger: `officecli dump file.pdf /`, `officecli dump file.odt /`, `officecli dump file.doc /` (legacy .doc, not .docx).

Common situations: User points dump at a PDF or legacy Office format; a script passes any file without checking the extension; confusion between .doc and .docx; an ODF file mistaken for OOXML.

Related errors


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