getzola/zola · error

op="fit_width" requires a `width` argument

Error message

op="fit_width" requires a `width` argument

What it means

`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"`.

Source

Thrown at components/imageproc/src/ops.rs:33

    /// that it fits within the specified width and height preserving aspect ratio.
    /// Either dimension may end up being smaller, but never larger than specified.
    Fit(u32, u32),
    /// Scales the image such that it fills the specified width and height.
    /// Output will always have the exact dimensions specified.
    /// The part of the image that doesn't fit in the thumbnail due to differing
    /// aspect ratio will be cropped away, if any.
    Fill(u32, u32),
}

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()),

View on GitHub (pinned to 61d3082821)

Solutions

  1. Add the required `width` argument alongside `op="fit_width"`
  2. If you intended to constrain by height instead, use `op="fit_height"` with a `height` argument
  3. Validate the parameter set before invoking the resize

Example fix

// before
image_resize(op="fit_width", height=300)
// after
image_resize(op="fit_width", width=300)
Defensive patterns

Strategy: validation

Validate before calling

const OP_ARG_REQS = {
  fit_width:  ["width"],
  fit_height: ["height"],
  scale:      ["width", "height"],
  fit:        ["width", "height"],
  fill:       ["width", "height"],
};
function validateResize(op, args) {
  const req = OP_ARG_REQS[op] || [];
  const missing = req.filter((k) => args[k] == null);
  if (missing.length) throw new Error(`op="${op}" missing: ${missing.join(", ")}`);
}

Type guard

fn is_fit_width_args(op: &str, args: &ResizeArgs) -> bool {
    op == "fit_width" && args.width.is_some()
}

Try / catch

match ResizeOperation::from_args(op, width, height) {
    Ok(op) => apply(op),
    Err(e) if e.to_string().contains("requires a `width`") => {
        log::error!("resize URL missing width for {op}");
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

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 getzola/zola@61d3082821 (2026-09-03). Data as JSON: /api/errors/d98e53b97b3c6b39. Report an issue: GitHub.