{"record":{"id":"d98e53b97b3c6b39","repo":"getzola/zola","slug":"op-fit-width-requires-a-width-argument","errorCode":null,"errorMessage":"op=\"fit_width\" requires a `width` argument","messagePattern":"op=\"fit_width\" requires a `width` argument","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"components/imageproc/src/ops.rs","lineNumber":33,"sourceCode":"    /// that it fits within the specified width and height preserving aspect ratio.\n    /// Either dimension may end up being smaller, but never larger than specified.\n    Fit(u32, u32),\n    /// Scales the image such that it fills the specified width and height.\n    /// Output will always have the exact dimensions specified.\n    /// The part of the image that doesn't fit in the thumbnail due to differing\n    /// aspect ratio will be cropped away, if any.\n    Fill(u32, u32),\n}\n\nimpl ResizeOperation {\n    pub fn from_args(op: &str, width: Option<u32>, height: Option<u32>) -> Result<Self> {\n        use ResizeOperation::*;\n\n        // Validate args:\n        match op {\n            \"fit_width\" => {\n                if width.is_none() {\n                    return Err(anyhow!(\"op=\\\"fit_width\\\" requires a `width` argument\"));\n                }\n            }\n            \"fit_height\" => {\n                if height.is_none() {\n                    return Err(anyhow!(\"op=\\\"fit_height\\\" requires a `height` argument\"));\n                }\n            }\n            \"scale\" | \"fit\" | \"fill\" => {\n                if width.is_none() || height.is_none() {\n                    return Err(anyhow!(\"op={} requires a `width` and `height` argument\", op));\n                }\n            }\n            _ => return Err(anyhow!(\"Invalid image resize operation: {}\", op)),\n        };\n\n        Ok(match op {\n            \"scale\" => Scale(width.unwrap(), height.unwrap()),\n            \"fit_width\" => FitWidth(width.unwrap()),","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/getzola/zola/blob/61d30828217957120309db657950224edf9707e2/components/imageproc/src/ops.rs#L15-L51","documentation":"`ResizeOperation::from_args` validates that the resize operation's required arguments are present before constructing the enum. The `fit_width` operation scales an image to a target width, so it needs a `width` argument; this error is thrown when `width` is `None` while `op=\"fit_width\"`.","triggerScenarios":"Requesting/configuring a resize with `op=\"fit_width\"` but omitting the `width` parameter (e.g. a URL like `...op=fit_height&width=...` mismatch, or config where width key is missing).","commonSituations":"Image resize URL built programmatically where the width parameter was dropped or renamed; copying a fit_height config and only changing op to fit_width without swapping the dimension argument.","solutions":["Add the required `width` argument alongside `op=\"fit_width\"`","If you intended to constrain by height instead, use `op=\"fit_height\"` with a `height` argument","Validate the parameter set before invoking the resize"],"exampleFix":"// before\nimage_resize(op=\"fit_width\", height=300)\n// after\nimage_resize(op=\"fit_width\", width=300)","handlingStrategy":"validation","validationCode":"const OP_ARG_REQS = {\n  fit_width:  [\"width\"],\n  fit_height: [\"height\"],\n  scale:      [\"width\", \"height\"],\n  fit:        [\"width\", \"height\"],\n  fill:       [\"width\", \"height\"],\n};\nfunction validateResize(op, args) {\n  const req = OP_ARG_REQS[op] || [];\n  const missing = req.filter((k) => args[k] == null);\n  if (missing.length) throw new Error(`op=\"${op}\" missing: ${missing.join(\", \")}`);\n}","typeGuard":"fn is_fit_width_args(op: &str, args: &ResizeArgs) -> bool {\n    op == \"fit_width\" && args.width.is_some()\n}","tryCatchPattern":"match ResizeOperation::from_args(op, width, height) {\n    Ok(op) => apply(op),\n    Err(e) if e.to_string().contains(\"requires a `width`\") => {\n        log::error!(\"resize URL missing width for {op}\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Centralize image resize URL construction in one helper so op/argument pairing is enforced","Add a test matrix of (op, args) combinations mirroring from_args validation","Fail fast at config parse time rather than at image processing time"],"tags":["configuration","image-resize","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"61d30828217957120309db657950224edf9707e2","analyzedAt":"2026-09-03T14:39:09.727Z","contentChangedAt":"2026-09-03T14:39:09.727Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}