sigoden/aichat · error · anyhow::Error
Invalid wrap value
Error message
Invalid wrap value
What it means
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.
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)
Example fix
// before (config) wrap = "80ch" // after wrap = 80
Defensive patterns
Strategy: validation
Validate before calling
fn valid_wrap(v: &str) -> bool {
v == "auto" || v.parse::<u16>().is_ok()
} Try / catch
match init_renderer() {
Err(e) if e.to_string().contains("Invalid wrap value") => {
eprintln!("wrap must be 'auto' or a number <= 65535; falling back to auto");
init_with_wrap_auto()
}
other => other,
} Prevention
- 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
When it happens
Trigger: Setting wrap to a non-numeric string (other than 'auto') in config or the --wrap flag while stdout is a terminal with detectable columns.
Common situations: Config containing wrap = "80ch" or "wide"; typo like "8o"; passing a value larger than u16 range (e.g. 99999).
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- No models
- Unknown client
- Unknown model
- Please enable function calling before using the agent.
- No available model
AI-assisted analysis of sigoden/aichat@82976d349a (2026-09-09).
Data as JSON: /api/errors/8412b2bef386351a.
Report an issue: GitHub.
Appendix: source
Thrown at src/render/markdown.rs:53
let syntax_set: SyntaxSet =
decode_bin(SYNTAXES).with_context(|| "MarkdownRender: invalid syntaxes binary")?;
let code_color = options
.theme
.as_ref()
.map(|theme| get_code_color(theme, options.truecolor));
let md_syntax = syntax_set.find_syntax_by_extension("md").unwrap().clone();
let line_type = LineType::Normal;
let wrap_width = match options.wrap.as_deref() {
None => None,
Some(value) => match terminal::size() {
Ok((columns, _)) => {
if value == "auto" {
Some(columns)
} else {
let value = value
.parse::<u16>()
.map_err(|_| anyhow!("Invalid wrap value"))?;
Some(columns.min(value))
}
}
Err(_) => None,
},
};
Ok(Self {
syntax_set,
code_color,
md_syntax,
code_syntax: None,
prev_line_type: line_type,
wrap_width,
options,
})
}
pub fn render(&mut self, text: &str) -> String {View on GitHub (pinned to 82976d349a)