getzola/zola · error
op={} requires a `width` and `height` argument
Error message
op={} requires a `width` and `height` argument What it means
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.
Source
Thrown at components/imageproc/src/ops.rs:43
impl ResizeOperation {
pub fn from_args(op: &str, width: Option<u32>, height: Option<u32>) -> Result<Self> {
use ResizeOperation::*;
// Validate args:
match op {
"fit_width" => {
if width.is_none() {
return Err(anyhow!("op=\"fit_width\" requires a `width` argument"));
}
}
"fit_height" => {
if height.is_none() {
return Err(anyhow!("op=\"fit_height\" requires a `height` argument"));
}
}
"scale" | "fit" | "fill" => {
if width.is_none() || height.is_none() {
return Err(anyhow!("op={} requires a `width` and `height` argument", op));
}
}
_ => return Err(anyhow!("Invalid image resize operation: {}", op)),
};
Ok(match op {
"scale" => Scale(width.unwrap(), height.unwrap()),
"fit_width" => FitWidth(width.unwrap()),
"fit_height" => FitHeight(height.unwrap()),
"fit" => Fit(width.unwrap(), height.unwrap()),
"fill" => Fill(width.unwrap(), height.unwrap()),
_ => unreachable!(),
})
}
}
/// Contains image crop/resize instructions for use by `Processor`
///View on GitHub (pinned to 61d3082821)
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
Example fix
// before image_resize(op="fit", width=300) // after image_resize(op="fit", width=300, height=200)
Defensive patterns
Strategy: validation
Validate before calling
function validateResize(op, width, height) {
const bothRequired = ["scale", "fit", "fill"].includes(op);
if (bothRequired && (width == null || height == null)) {
throw new Error(`op=${op} requires width and height`);
}
if (width == null && height == null) {
throw new Error("resize needs at least one dimension");
}
} Type guard
fn has_both_dimensions(width: Option<u32>, height: Option<u32>) -> bool {
width.is_some() && height.is_some()
} Try / catch
match ResizeOperation::from_args(op, width, height) {
Ok(op) => apply(op),
Err(e) if e.to_string().contains("width and height") => {
log::error!("op {op} needs both dimensions");
}
Err(e) => return Err(e),
} Prevention
- 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
When it happens
Trigger: Using `op="scale"`, `op="fit"`, or `op="fill"` with only one of width/height supplied (or neither).
Common situations: 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.
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
- op="fit_width" requires a `width` argument
- op="fit_height" requires a `height` argument
- Invalid image resize operation: {}
- Invalid image format: {}
- Theme `{}` is missing a templates folder
AI-assisted analysis of getzola/zola@61d3082821 (2026-09-03).
Data as JSON: /api/errors/6cbc1a0a6965cda0.
Report an issue: GitHub.