jdx/mise · error

replace requires exactly 3 arguments

Error message

replace requires exactly 3 arguments

What it means

Validation bail in the aqua template function registry: replace was invoked with an argument count other than 3 (search, replacement, text). It guards arity when evaluating aqua package template expressions.

Source

Thrown at crates/aqua-registry/src/template.rs:389

        Ok(Box::new(StringValue(
            text.strip_prefix(&prefix).unwrap_or(&text).to_string(),
        )) as Box<dyn Value>)
    });

    registry.insert("trimSuffix", |args| {
        if args.len() != 2 {
            bail!("trimSuffix requires exactly 2 arguments");
        }
        let suffix = args[0].as_string();
        let text = args[1].as_string();
        Ok(Box::new(StringValue(
            text.strip_suffix(&suffix).unwrap_or(&text).to_string(),
        )) as Box<dyn Value>)
    });

    registry.insert("replace", |args| {
        if args.len() != 3 {
            bail!("replace requires exactly 3 arguments");
        }
        let from = args[0].as_string();
        let to = args[1].as_string();
        let text = args[2].as_string();
        Ok(Box::new(StringValue(text.replace(&from, &to))) as Box<dyn Value>)
    });

    registry
});

/// Evaluator walks the AST and produces results
struct Evaluator<'a> {
    ctx: &'a Context,
}

impl<'a> Evaluator<'a> {
    fn new(ctx: &'a Context) -> Self {
        Self { ctx }

View on GitHub (pinned to afd2eddd3a)

Solutions

  1. Provide all three arguments in order: `{{ replace windows darwin .Filename }}`
  2. Chain multiple replace calls (one each) rather than passing pairs

Example fix

// before
{{ replace windows darwin .Filename }}
// after
{{ replace windows darwin .Filename }} -> {{ replace from to text }}
Defensive patterns

Strategy: validation

Validate before calling

fn check_replace_args(args: &[Value]) -> Result<(), String> {
    if args.len() != 3 {
        return Err(format!("replace needs exactly 3 arguments, got {}", args.len()));
    }
    Ok(())
}

Try / catch

match f(&args) {
    Ok(v) => v,
    Err(e) if e.to_string().contains("replace requires exactly 3 arguments") => {
        eprintln!("{}", e); args_fallback
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Expressions like `{{ replace windows darwin }}` (two arguments) or `{{ replace a b c d }}` (four) evaluated through the registry.

Common situations: Rewriting OS/arch tokens in asset URL templates and adding or losing one of the three required values; going back and forth with string concatenation.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of jdx/mise@afd2eddd3a (2026-09-09). Data as JSON: /api/errors/bd7694f9a5470c12. Report an issue: GitHub.