{"record":{"id":"84d932c0a8c5e805","repo":"iOfficeAI/OfficeCLI","slug":"invalid-value-84d932","errorCode":"invalid_value","errorMessage":"Unknown mode: {mode}. Available: text, annotated, outline, stats, issues, html, svg, screenshot, forms","messagePattern":"Unknown mode: (.+?)\\. Available: text, annotated, outline, stats, issues, html, svg, screenshot, forms","errorType":"exception","errorClass":"CliException","httpStatus":null,"severity":"error","filePath":"src/officecli/CommandBuilder.View.cs","lineNumber":658,"sourceCode":"                    if (handler is OfficeCli.Handlers.WordHandler wordFormsHandler)\n                        Console.WriteLine(OutputFormatter.WrapEnvelope(wordFormsHandler.ViewAsFormsJson().ToJsonString(OutputFormatter.PublicJsonOptions)));\n                    else if (handler is OfficeCli.Core.Plugins.FormatHandlerProxy formsProxy)\n                    {\n                        var formsJson = formsProxy.ViewAsFormsJson();\n                        if (formsJson is null)\n                            throw new OfficeCli.Core.CliException($\"Forms view is not supported by the format-handler plugin for {file.Extension}.\")\n                            { Code = \"unsupported_type\" };\n                        Console.WriteLine(OutputFormatter.WrapEnvelope(formsJson.ToJsonString(OutputFormatter.PublicJsonOptions)));\n                    }\n                    else\n                        throw new OfficeCli.Core.CliException(\"Forms view is only supported for .docx files.\")\n                        {\n                            Code = \"unsupported_type\",\n                            ValidValues = [\"text\", \"annotated\", \"outline\", \"stats\", \"issues\", \"html\", \"svg\", \"screenshot\", \"pdf\", \"forms\"]\n                        };\n                }\n                else\n                    throw new OfficeCli.Core.CliException($\"Unknown mode: {mode}. Available: text, annotated, outline, stats, issues, html, svg, screenshot, forms\")\n                    {\n                        Code = \"invalid_value\",\n                        ValidValues = [\"text\", \"annotated\", \"outline\", \"stats\", \"issues\", \"html\", \"svg\", \"screenshot\", \"pdf\", \"forms\"]\n                    };\n            }\n            else\n            {\n                var output = mode.ToLowerInvariant() switch\n                {\n                    \"text\" or \"t\" => handler.ViewAsText(start, end, maxLines, cols, clipArg),\n                    \"annotated\" or \"a\" => handler.ViewAsAnnotated(start, end, maxLines, cols),\n                    \"outline\" or \"o\" => handler.ViewAsOutline(),\n                    \"stats\" or \"s\" => withPagesValue.HasValue\n                        ? $\"Pages: {withPagesValue}\\n\" + handler.ViewAsStats()\n                        : handler.ViewAsStats(),\n                    \"issues\" or \"i\" => OutputFormatter.FormatIssues(handler.ViewAsIssues(issueType, limit), OutputFormat.Text),\n                    \"forms\" or \"f\" => handler switch\n                    {","sourceCodeStart":640,"sourceCodeEnd":676,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/CommandBuilder.View.cs#L640-L676","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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).","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)"],"exampleFix":"// before\nofficecli view --mode stat --json doc.docx   // typo\n// after\nofficecli view --mode stats --json doc.docx","handlingStrategy":"validation","validationCode":"// Validate mode against the known set before invoking under --json.\nstatic readonly HashSet<string> ValidModes = new(StringComparer.OrdinalIgnoreCase)\n{ \"text\",\"annotated\",\"outline\",\"stats\",\"issues\",\"html\",\"svg\",\"screenshot\",\"forms\",\"pdf\",\n  \"t\",\"a\",\"o\",\"s\",\"i\",\"f\",\"g\" };\nif (!ValidModes.Contains(mode))\n{\n    // reject and prompt for a valid mode\n}","typeGuard":"bool IsValidMode(string mode) =>\n    mode.ToLowerInvariant() is \"text\" or \"t\" or \"annotated\" or \"a\" or \"outline\" or \"o\"\n    or \"stats\" or \"s\" or \"issues\" or \"i\" or \"html\" or \"svg\" or \"g\"\n    or \"screenshot\" or \"forms\" or \"f\" or \"pdf\";","tryCatchPattern":"try\n{\n    // invoke view --mode X --json file\n}\ncatch (OfficeCli.Core.CliException ex) when (ex.Code == \"invalid_value\")\n{\n    // mode was unrecognized; use a value from ex.ValidValues\n}","preventionTips":["Validate --mode against the documented set before invoking","Use supported single-letter aliases to reduce typos","Quote --mode and verify shell expansion in scripts"],"tags":["invalid-value","mode","json","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}