{"record":{"id":"6cbc1a0a6965cda0","repo":"getzola/zola","slug":"op-requires-a-width-and-height-argument","errorCode":null,"errorMessage":"op={} requires a `width` and `height` argument","messagePattern":"op=(.+?) requires a `width` and `height` argument","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"components/imageproc/src/ops.rs","lineNumber":43,"sourceCode":"impl 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()),\n            \"fit_height\" => FitHeight(height.unwrap()),\n            \"fit\" => Fit(width.unwrap(), height.unwrap()),\n            \"fill\" => Fill(width.unwrap(), height.unwrap()),\n            _ => unreachable!(),\n        })\n    }\n}\n\n/// Contains image crop/resize instructions for use by `Processor`\n///","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/getzola/zola/blob/61d30828217957120309db657950224edf9707e2/components/imageproc/src/ops.rs#L25-L61","documentation":"For `scale`, `fit`, and `fill` operations, both a target width and height are required because these produce exact-dimension outputs. `ResizeOperation::from_args` throws this error when either `width` or `height` is `None` for one of these ops.","triggerScenarios":"Using `op=\"scale\"`, `op=\"fit\"`, or `op=\"fill\"` with only one of width/height supplied (or neither).","commonSituations":"Template or config copy where one dimension was deleted; form/URL query strings where a dimension parameter is conditionally absent; switching from fit_width to fill without adding height.","solutions":["Supply both `width` and `height` arguments for scale/fit/fill","Or switch to `fit_width`/`fit_height` if only one dimension should constrain the result","Add pre-validation that checks both dimensions exist before selecting these ops"],"exampleFix":"// before\nimage_resize(op=\"fit\", width=300)\n// after\nimage_resize(op=\"fit\", width=300, height=200)","handlingStrategy":"validation","validationCode":"function validateResize(op, width, height) {\n  const bothRequired = [\"scale\", \"fit\", \"fill\"].includes(op);\n  if (bothRequired && (width == null || height == null)) {\n    throw new Error(`op=${op} requires width and height`);\n  }\n  if (width == null && height == null) {\n    throw new Error(\"resize needs at least one dimension\");\n  }\n}","typeGuard":"fn has_both_dimensions(width: Option<u32>, height: Option<u32>) -> bool {\n    width.is_some() && height.is_some()\n}","tryCatchPattern":"match ResizeOperation::from_args(op, width, height) {\n    Ok(op) => apply(op),\n    Err(e) if e.to_string().contains(\"width and height\") => {\n        log::error!(\"op {op} needs both dimensions\");\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","Prefer fit_width/fit_height when only one dimension is semantically required"],"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"}