sigoden/aichat · error · anyhow::Error

Invalid wrap value

Error message

Invalid wrap value

What it means

Validation error in GlobalConfig::set_wrap when the value is neither 'no', 'auto', nor parseable as u16. The wrap setting accepts only those three forms; anything else fails the integer parse and bails. The input at fault is the malformed wrap value string.

Solutions

  1. Pass a plain integer width (e.g. `80`).
  2. Use `auto` for automatic width detection.
  3. Use null/unset to disable wrapping.
  4. Ensure the number fits in 0–65535 (u16).

Example fix

// before
config.set_wrap("80ch")?;

// after
config.set_wrap("80")?; // or "auto"
Defensive patterns

Strategy: validation

Validate before calling

// Rust
fn is_valid_wrap(v: &str) -> bool {
    v == "auto" || v.parse::<u16>().is_ok()
}

Try / catch

// REPL usage
if !is_valid_wrap(input) { eprintln!("Usage: /wrap auto|<width 0-65535>"); }

Prevention

When it happens

Trigger: Calling `set_wrap` with a string that is neither "auto"/null nor a valid u16 (e.g. "80ch", "true", "1_000", "70000" which overflows u16, or a negative number).

Common situations: Typing `/wrap 80ch` or `/wrap none` in the REPL; pasting a width beyond 65535; config file containing a wrapped string value.

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


AI-assisted analysis of sigoden/aichat@82976d349a (2026-09-09). Data as JSON: /api/errors/070dd3fe0da83ab8. Report an issue: GitHub.

Appendix: source

Thrown at src/config/mod.rs:838

        match has_rag {
            true => update_rag(config, |rag| {
                rag.set_top_k(value)?;
                Ok(())
            })?,
            false => config.write().rag_top_k = value,
        }
        Ok(())
    }

    pub fn set_wrap(&mut self, value: &str) -> Result<()> {
        if value == "no" {
            self.wrap = None;
        } else if value == "auto" {
            self.wrap = Some(value.into());
        } else {
            value
                .parse::<u16>()
                .map_err(|_| anyhow!("Invalid wrap value"))?;
            self.wrap = Some(value.into())
        }
        Ok(())
    }

    pub fn set_max_output_tokens(&mut self, value: Option<isize>) {
        match self.role_like_mut() {
            Some(role_like) => {
                let mut model = role_like.model().clone();
                model.set_max_tokens(value, true);
                role_like.set_model(model);
            }
            None => {
                self.model.set_max_tokens(value, true);
            }
        };
    }

View on GitHub (pinned to 82976d349a)