getzola/zola · error

Invalid image resize operation: {}

Error message

Invalid image resize operation: {}

What it means

After validating required arguments, `ResizeOperation::from_args` maps the op string to an enum variant. Any op string not in {fit_width, fit_height, scale, fit, fill} hits the `_` arm and fails with this error listing the invalid op.

Source

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

        // 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`
///
/// The `Processor` applies `crop` first, if any, and then `resize`, if any.
#[derive(Clone, PartialEq, Eq, Hash, Default, Debug)]
pub struct ResizeInstructions {

View on GitHub (pinned to 61d3082821)

Solutions

  1. Correct the op string to one of the supported values: scale, fit, fit_width, fit_height, fill
  2. Check the documentation for your installed version for the exact op names
  3. Validate user-supplied op values against an allowlist before calling

Example fix

// before
image_resize(op="resize", width=300, height=200)
// after
image_resize(op="scale", width=300, height=200)
Defensive patterns

Strategy: validation

Validate before calling

const OPS = new Set(["scale", "fit", "fit_width", "fit_height", "fill"]);
function isValidOp(op) {
  return OPS.has(op);
}
if (!isValidOp(op)) throw new Error(`unknown resize op: ${op}; use ${[...OPS].join("|")}`);

Type guard

fn is_valid_resize_op(op: &str) -> bool {
    matches!(op, "scale" | "fit" | "fit_width" | "fit_height" | "fill")
}

Try / catch

match ResizeOperation::from_args(op, width, height) {
    Ok(op) => apply(op),
    Err(e) if e.to_string().starts_with("Invalid image resize operation") => {
        log::error!("unknown op '{}'; use scale|fit|fit_width|fit_height|fill", op);
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Passing an unknown or misspelled resize operation name, e.g. `op="resize"`, `op="crop"`, `op="Fit"` (case mismatch), or `op="fit-width"` (wrong separator).

Common situations: Typos in template image resize calls; copying op names from other image libraries (sharp, ImageMagick) that use different vocabulary; version differences where an op was renamed or removed.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of getzola/zola@61d3082821 (2026-09-03). Data as JSON: /api/errors/d7193adbcf2eb0ce. Report an issue: GitHub.