{"record":{"id":"d1d0e0fcca0e6e84","repo":"vercel/next.js","slug":"unknown-unit-unit","errorCode":null,"errorMessage":"Unknown unit {unit}","messagePattern":"Unknown unit (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"turbopack/crates/turbopack-image/src/process/svg.rs","lineNumber":49,"sourceCode":"    LazyLock::new(|| Regex::new(r#\"\\swidth=['\"]([^%]+?)['\"]\"#).unwrap());\nstatic HEIGHT_REGEX: LazyLock<Regex> =\n    LazyLock::new(|| Regex::new(r#\"\\sheight=['\"]([^%]+?)['\"]\"#).unwrap());\nstatic VIEW_BOX_REGEX: LazyLock<Regex> =\n    LazyLock::new(|| Regex::new(r#\"\\sviewBox=['\"](.+?)['\"]\"#).unwrap());\nstatic VIEW_BOX_CONTENT_REGEX: LazyLock<Regex> = LazyLock::new(|| {\n    Regex::new(r\"^\\s*((?:\\w|\\.|-)+)\\s+((?:\\w|\\.|-)+)\\s+((?:\\w|\\.|-)+)\\s+((?:\\w|\\.|-)+)\\s*$\")\n        .unwrap()\n});\n\nfn parse_length(len: &str) -> Result<f64> {\n    let captures = UNIT_REGEX\n        .captures(len)\n        .ok_or_else(|| anyhow!(\"Unknown syntax for length, expected value with unit ({len})\"))?;\n    let val = captures[1].parse::<f64>()?;\n    let unit = &captures[2];\n    let unit_scale = UNITS\n        .get(unit)\n        .ok_or_else(|| anyhow!(\"Unknown unit {unit}\"))?;\n    Ok(val * unit_scale)\n}\n\nfn parse_viewbox(viewbox: &str) -> Result<(f64, f64)> {\n    let captures = VIEW_BOX_CONTENT_REGEX\n        .captures(viewbox)\n        .ok_or_else(|| anyhow!(\"Unknown syntax for viewBox ({viewbox})\"))?;\n    let width = parse_length(&captures[3])?;\n    let height = parse_length(&captures[4])?;\n    Ok((width, height))\n}\n\nfn calculate_by_viewbox(\n    view_box: (f64, f64),\n    width: Option<Result<f64>>,\n    height: Option<Result<f64>>,\n) -> Result<(u32, u32)> {\n    let ratio = view_box.0 / view_box.1;","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/turbopack/crates/turbopack-image/src/process/svg.rs#L31-L67","documentation":"After matching a numeric value, parse_length looks up the captured unit string in the UNITS map (in, cm, em, ex, m, mm, pc, pt, px, and empty). If the unit is not found, this error fires. In practice the upstream regex already constrains the unit to the known set or empty, so this is a defensive guard that is rarely reached through normal input.","triggerScenarios":"Reachable only if the UNIT_REGEX capture group yields a unit token absent from the UNITS phf map — essentially an internal inconsistency or a regex/map desync. Normal malformed input is caught earlier by the 'Unknown syntax for length' error (283).","commonSituations":"Essentially unreachable via user-supplied SVGs because the regex whitelists units; would only surface from a code change that adds a unit to the regex without updating the UNITS map.","solutions":["This usually indicates a Turbopack internal bug — file an issue with the SVG that triggered it.","As a user workaround, normalize the SVG width/height to a plain number (no unit) so the empty-unit path is taken."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Defensive check: ensure the unit is in the supported set.\nconst UNITS = new Set(['in','cm','em','ex','m','mm','pc','pt','px','']);\nfunction hasSupportedUnit(v) {\n  const m = /^([0-9.]+(?:e-?\\d+)?)(in|cm|em|ex|m|mm|pc|pt|px)?$/.exec((v||'').trim());\n  return !!m && UNITS.has(m[2]);\n}\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize SVG dimensions to unitless numbers to sidestep both the syntax and unit checks.","If this error appears, suspect a Turbopack regression and report the exact SVG."],"tags":["svg","image-size","units","internal"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}