{"record":{"id":"8412b2bef386351a","repo":"sigoden/aichat","slug":"invalid-wrap-value-8412b2","errorCode":null,"errorMessage":"Invalid wrap value","messagePattern":"Invalid wrap value","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/render/markdown.rs","lineNumber":53,"sourceCode":"        let syntax_set: SyntaxSet =\n            decode_bin(SYNTAXES).with_context(|| \"MarkdownRender: invalid syntaxes binary\")?;\n\n        let code_color = options\n            .theme\n            .as_ref()\n            .map(|theme| get_code_color(theme, options.truecolor));\n        let md_syntax = syntax_set.find_syntax_by_extension(\"md\").unwrap().clone();\n        let line_type = LineType::Normal;\n        let wrap_width = match options.wrap.as_deref() {\n            None => None,\n            Some(value) => match terminal::size() {\n                Ok((columns, _)) => {\n                    if value == \"auto\" {\n                        Some(columns)\n                    } else {\n                        let value = value\n                            .parse::<u16>()\n                            .map_err(|_| anyhow!(\"Invalid wrap value\"))?;\n                        Some(columns.min(value))\n                    }\n                }\n                Err(_) => None,\n            },\n        };\n        Ok(Self {\n            syntax_set,\n            code_color,\n            md_syntax,\n            code_syntax: None,\n            prev_line_type: line_type,\n            wrap_width,\n            options,\n        })\n    }\n\n    pub fn render(&mut self, text: &str) -> String {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/render/markdown.rs#L35-L71","documentation":"Error path in MarkdownRender::init: the configured wrap option value is compared against the actual terminal width, and when the wrap specification cannot be reconciled with the terminal size (invalid or out-of-range value), initialization fails with 'Invalid wrap value'. The input at fault is the options.wrap string.","triggerScenarios":"Setting wrap to a non-numeric string (other than 'auto') in config or the --wrap flag while stdout is a terminal with detectable columns.","commonSituations":"Config containing wrap = \"80ch\" or \"wide\"; typo like \"8o\"; passing a value larger than u16 range (e.g. 99999).","solutions":["Set wrap to a plain number of columns, e.g. 80","Use wrap = \"auto\" to follow terminal width","Ensure the value fits in u16 (0–65535)"],"exampleFix":"// before (config)\nwrap = \"80ch\"\n// after\nwrap = 80","handlingStrategy":"validation","validationCode":"fn valid_wrap(v: &str) -> bool {\n    v == \"auto\" || v.parse::<u16>().is_ok()\n}","typeGuard":null,"tryCatchPattern":"match init_renderer() {\n    Err(e) if e.to_string().contains(\"Invalid wrap value\") => {\n        eprintln!(\"wrap must be 'auto' or a number <= 65535; falling back to auto\");\n        init_with_wrap_auto()\n    }\n    other => other,\n}","preventionTips":["Only use 'auto' or a bare u16 number for wrap","Validate config values at load time with a schema","Avoid pasting values with units (ch, px) into terminal-width settings"],"tags":["config","rendering","terminal"],"backgroundTag":"invalid-config-value","analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}