{"record":{"id":"dd714e336d995592","repo":"windmill-labs/windmill","slug":"hex-string-did-not-decode-to-an-u64-s","errorCode":null,"errorMessage":"hex string did not decode to an u64: {s}","messagePattern":"hex string did not decode to an u64: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/windmill-types/src/scripts.rs","lineNumber":738,"sourceCode":"    let languages: Vec<ScriptLang> = s\n        .split(\",\")\n        .map(ScriptLang::from_str)\n        .try_collect()\n        .map_err(|e: anyhow::Error| serde::de::Error::custom(e.to_string()))?;\n\n    let languages = if languages.is_empty() {\n        None\n    } else {\n        Some(languages)\n    };\n\n    Ok(languages)\n}\n\npub fn to_i64(s: &str) -> anyhow::Result<i64> {\n    let v = hex::decode(s)?;\n    if v.len() < 8 {\n        return Err(anyhow::anyhow!(\"hex string did not decode to an u64: {s}\",));\n    }\n    let nb: u64 = u64::from_be_bytes(\n        v[0..8]\n            .try_into()\n            .map_err(|_| hex::FromHexError::InvalidStringLength)?,\n    );\n    Ok(nb as i64)\n}\n\npub fn to_hex_string(i: &i64) -> String {\n    hex::encode(i.to_be_bytes())\n}\n\n#[derive(Deserialize, Serialize)]\npub struct HubScript {\n    pub content: String,\n    pub lockfile: Option<String>,\n    pub language: ScriptLang,","sourceCodeStart":720,"sourceCodeEnd":756,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/windmill-types/src/scripts.rs#L720-L756","documentation":"to_i64 decodes a hex string expected to encode a 64-bit big-endian integer. If hex::decode succeeds but yields fewer than 8 bytes, the string cannot represent a u64 and this error is returned (note the message says u64 although the function returns i64).","triggerScenarios":"Passing a hex string shorter than 16 hex chars (fewer than 8 bytes) to to_i64 — e.g. a truncated hash prefix or a malformed encoded integer.","commonSituations":"Storing/truncating encoded values in the database; hand-constructed hex ids; mismatched encoding between writer and reader.","solutions":["Ensure the hex string encodes a full 8-byte value (16 hex characters)","Regenerate the value at the source instead of truncating it","Verify hex::decode succeeded (invalid chars would fail earlier with a hex error)","Also confirm the string has no `0x` prefix, which decode rejects"],"exampleFix":"// before\nlet n = windmill::to_i64(\"abcd\")?; // 2 bytes\n// after\nlet n = windmill::to_i64(\"000000000000abcd\")?; // 8 bytes","handlingStrategy":"validation","validationCode":"def ensure_u64_hex(s: str) -> str:\n    body = s[2:] if s.startswith(\"0x\") else s\n    if len(body) != 16 or any(c not in \"0123456789abcdefABCDEF\" for c in body):\n        raise ValueError(f\"expected 16 hex chars encoding a u64, got {s!r}\")\n    return body.lower()","typeGuard":null,"tryCatchPattern":"match windmill_types::scripts::to_i64(s) {\n    Err(e) if e.to_string().contains(\"hex string did not decode\") => {\n        eprintln!(\"value {s} is not a full 8-byte hex encoding\");\n    }\n    other => other?,\n}","preventionTips":["Never truncate encoded integer hex strings","Zero-pad to 16 hex chars when serializing","Strip 0x prefixes before decoding","Add a round-trip encode/decode test for persisted values"],"tags":["rust","parsing","hex","encoding"],"backgroundTag":"invalid-hex-encoding","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}