iOfficeAI/OfficeCLI · error · CliException
invalid_value
invalid_value
Error message
Unknown mode: {mode}. Available: text, annotated, outline, stats, issues, html, svg, screenshot, forms What it means
JSON-output final guard for the mode switch: the lowercased mode matched none of stats/outline/text/annotated/issues/forms (html/svg/screenshot/pdf are handled in earlier branches before this switch). The thrown message lists the available modes (note: the message text omits 'pdf' but ValidValues includes it — a minor inconsistency). invalid_value guides the caller to a valid mode string.
Source
Thrown at src/officecli/CommandBuilder.View.cs:658
if (handler is OfficeCli.Handlers.WordHandler wordFormsHandler)
Console.WriteLine(OutputFormatter.WrapEnvelope(wordFormsHandler.ViewAsFormsJson().ToJsonString(OutputFormatter.PublicJsonOptions)));
else if (handler is OfficeCli.Core.Plugins.FormatHandlerProxy formsProxy)
{
var formsJson = formsProxy.ViewAsFormsJson();
if (formsJson is null)
throw new OfficeCli.Core.CliException($"Forms view is not supported by the format-handler plugin for {file.Extension}.")
{ Code = "unsupported_type" };
Console.WriteLine(OutputFormatter.WrapEnvelope(formsJson.ToJsonString(OutputFormatter.PublicJsonOptions)));
}
else
throw new OfficeCli.Core.CliException("Forms view is only supported for .docx files.")
{
Code = "unsupported_type",
ValidValues = ["text", "annotated", "outline", "stats", "issues", "html", "svg", "screenshot", "pdf", "forms"]
};
}
else
throw new OfficeCli.Core.CliException($"Unknown mode: {mode}. Available: text, annotated, outline, stats, issues, html, svg, screenshot, forms")
{
Code = "invalid_value",
ValidValues = ["text", "annotated", "outline", "stats", "issues", "html", "svg", "screenshot", "pdf", "forms"]
};
}
else
{
var output = mode.ToLowerInvariant() switch
{
"text" or "t" => handler.ViewAsText(start, end, maxLines, cols, clipArg),
"annotated" or "a" => handler.ViewAsAnnotated(start, end, maxLines, cols),
"outline" or "o" => handler.ViewAsOutline(),
"stats" or "s" => withPagesValue.HasValue
? $"Pages: {withPagesValue}\n" + handler.ViewAsStats()
: handler.ViewAsStats(),
"issues" or "i" => OutputFormatter.FormatIssues(handler.ViewAsIssues(issueType, limit), OutputFormat.Text),
"forms" or "f" => handler switch
{View on GitHub (pinned to 1ced45e900)
Solutions
- Use one of: text, annotated, outline, stats, issues, html, svg, screenshot, forms, pdf
- Check for typos and unexpanded shell variables in --mode
- Use the documented single-letter alias where supported (t, a, o, s, i, f, g)
Example fix
// before officecli view --mode stat --json doc.docx // typo // after officecli view --mode stats --json doc.docx
Defensive patterns
Strategy: validation
Validate before calling
// Validate mode against the known set before invoking under --json.
static readonly HashSet<string> ValidModes = new(StringComparer.OrdinalIgnoreCase)
{ "text","annotated","outline","stats","issues","html","svg","screenshot","forms","pdf",
"t","a","o","s","i","f","g" };
if (!ValidModes.Contains(mode))
{
// reject and prompt for a valid mode
} Type guard
bool IsValidMode(string mode) =>
mode.ToLowerInvariant() is "text" or "t" or "annotated" or "a" or "outline" or "o"
or "stats" or "s" or "issues" or "i" or "html" or "svg" or "g"
or "screenshot" or "forms" or "f" or "pdf"; Try / catch
try
{
// invoke view --mode X --json file
}
catch (OfficeCli.Core.CliException ex) when (ex.Code == "invalid_value")
{
// mode was unrecognized; use a value from ex.ValidValues
} Prevention
- Validate --mode against the documented set before invoking
- Use supported single-letter aliases to reduce typos
- Quote --mode and verify shell expansion in scripts
When it happens
Trigger: `view --mode bogus --json doc.docx` — any unrecognized mode token under --json that wasn't intercepted by the earlier html/svg/screenshot/pdf branches. Also a mode with stray whitespace/case that survived ToLowerInvariant but isn't a recognized alias.
Common situations: Typo in --mode; using a mode name from a different tool version; shell expansion producing an unexpected token; abbreviations that aren't registered aliases (only single-letter aliases like t/a/o/s/i/f/g are accepted).
Related errors
- Batch input must be a JSON array. Got: {rootKind.ToString().
- batch item[{ri}]: unknown field(s) {string.Join(", ", unknow
- batch item[{ni}] is null. Each entry must be a JSON object (
- invalid_value
- invalid_value
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/84d932c0a8c5e805.
Report an issue: GitHub.