{"record":{"id":"bd7694f9a5470c12","repo":"jdx/mise","slug":"replace-requires-exactly-3-arguments","errorCode":null,"errorMessage":"replace requires exactly 3 arguments","messagePattern":"replace requires exactly 3 arguments","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/aqua-registry/src/template.rs","lineNumber":389,"sourceCode":"        Ok(Box::new(StringValue(\n            text.strip_prefix(&prefix).unwrap_or(&text).to_string(),\n        )) as Box<dyn Value>)\n    });\n\n    registry.insert(\"trimSuffix\", |args| {\n        if args.len() != 2 {\n            bail!(\"trimSuffix requires exactly 2 arguments\");\n        }\n        let suffix = args[0].as_string();\n        let text = args[1].as_string();\n        Ok(Box::new(StringValue(\n            text.strip_suffix(&suffix).unwrap_or(&text).to_string(),\n        )) as Box<dyn Value>)\n    });\n\n    registry.insert(\"replace\", |args| {\n        if args.len() != 3 {\n            bail!(\"replace requires exactly 3 arguments\");\n        }\n        let from = args[0].as_string();\n        let to = args[1].as_string();\n        let text = args[2].as_string();\n        Ok(Box::new(StringValue(text.replace(&from, &to))) as Box<dyn Value>)\n    });\n\n    registry\n});\n\n/// Evaluator walks the AST and produces results\nstruct Evaluator<'a> {\n    ctx: &'a Context,\n}\n\nimpl<'a> Evaluator<'a> {\n    fn new(ctx: &'a Context) -> Self {\n        Self { ctx }","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/crates/aqua-registry/src/template.rs#L371-L407","documentation":"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.","triggerScenarios":"Expressions like `{{ replace windows darwin }}` (two arguments) or `{{ replace a b c d }}` (four) evaluated through the registry.","commonSituations":"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.","solutions":["Provide all three arguments in order: `{{ replace windows darwin .Filename }}`","Chain multiple replace calls (one each) rather than passing pairs"],"exampleFix":"// before\n{{ replace windows darwin .Filename }}\n// after\n{{ replace windows darwin .Filename }} -> {{ replace from to text }}","handlingStrategy":"validation","validationCode":"fn check_replace_args(args: &[Value]) -> Result<(), String> {\n    if args.len() != 3 {\n        return Err(format!(\"replace needs exactly 3 arguments, got {}\", args.len()));\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"match f(&args) {\n    Ok(v) => v,\n    Err(e) if e.to_string().contains(\"replace requires exactly 3 arguments\") => {\n        eprintln!(\"{}\", e); args_fallback\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always supply from, to, and text as three separate arguments","Chain replace calls for multiple substitutions"],"tags":["template","arguments","string"],"backgroundTag":"missing-required-argument","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}