iOfficeAI/OfficeCLI · error · CliException

file_not_found

file_not_found

Error message

File not found: {file.FullName}. Use 'officecli create {file.FullName}' to create a blank document, or check the file extension.

What it means

Thrown by the `dump` command when the target document file does not exist on disk. Tagged CONSISTENCY(file-not-found): without this early guard, dump fell through to the SDK opener whose raw '.NET Could not find file' message disagreed with every other command. The guard (line 61-66) raises a CliException with code `file_not_found` and an actionable suggestion to run `create`.

Source

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

            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").
            // Mirrors the TryResident calls in `get`/`query`/`set`.
            if (TryResident(file.FullName, req =>
            {
                req.Command = "dump";
                req.Json = json;
                req.Args["path"] = path;
                req.Args["format"] = format;
                if (!string.IsNullOrEmpty(outPath)) req.Args["out"] = outPath!;
            }, json) is {} rc) return rc;

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Verify the path: `ls -l <file>` from OfficeCLI's cwd; use an absolute path.
  2. If the document does not exist yet, create it first: `officecli create <path>` (the error message suggests this).
  3. Fix the producing step so the file exists before dump runs.

Example fix

# before
officecli dump /misspelled.docx /

# after
officecli create ./report.docx
officecli dump ./report.docx /
Defensive patterns

Strategy: validation

Validate before calling

// Verify the target exists before dump.
if (!File.Exists(file.FullName))
    throw new FileNotFoundException($"File not found: {file.FullName}");

Type guard

// Guard: target document is present.
static bool DumpTargetReady(string path) => File.Exists(path);

Prevention

When it happens

Trigger: `officecli dump /missing.docx /`, or any dump against a path that does not resolve to an existing file (typo, wrong cwd, not-yet-created document).

Common situations: Typo in the document path; script runs from a different cwd so a relative path misses; the document was supposed to be generated by a prior step that failed; the file was deleted/moved between commands.

Related errors


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