{"record":{"id":"65ecc410c98ebaa3","repo":"clockworklabs/SpacetimeDB","slug":"data-key-not-found-in-return-object","errorCode":null,"errorMessage":"data key not found in return object","messagePattern":"data key not found in return object","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/core/src/host/v8/syscall/v1.rs","lineNumber":562,"sourceCode":"\n    // The original version returned a byte array with the encoded rows.\n    if ret.is_typed_array() && ret.is_uint8_array() {\n        // This is the original format, which just returns the raw bytes.\n        let ret =\n            cast!(scope, ret, v8::Uint8Array, \"bytes return from `__call_view_anon__`\").map_err(|e| e.throw(scope))?;\n        let bytes = ret.get_contents(&mut []);\n\n        return Ok(ViewReturnData::Rows(Bytes::copy_from_slice(bytes)));\n    };\n\n    // The newer version returns an object with a `data` field containing the bytes.\n    let ret = cast!(scope, ret, v8::Object, \"object return from `__call_view_anon__`\").map_err(|e| e.throw(scope))?;\n\n    let Some(data_key) = v8::String::new(scope, \"data\") else {\n        return Err(ErrorOrException::Err(anyhow::anyhow!(\"error creating a v8 string\")));\n    };\n    let Some(data_val) = ret.get(scope, data_key.into()) else {\n        return Err(ErrorOrException::Err(anyhow::anyhow!(\n            \"data key not found in return object\"\n        )));\n    };\n\n    let ret = cast!(\n        scope,\n        data_val,\n        v8::Uint8Array,\n        \"bytes in the `data` field returned from `__call_view_anon__`\"\n    )\n    .map_err(|e| e.throw(scope))?;\n    let bytes = ret.get_contents(&mut []);\n\n    Ok(ViewReturnData::HeaderFirst(Bytes::copy_from_slice(bytes)))\n}\n\n/// Calls the `__call_view_anon__` function `fun`.\npub(super) fn call_call_view_anon(","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/core/src/host/v8/syscall/v1.rs#L544-L580","documentation":"In the v1 syscall path for __call_view_anon__, a view may return raw bytes (legacy) or an object whose `data` field holds a Uint8Array. This branch handles the object form: ret.get(scope, 'data') returned None, so the returned object lacks the required `data` property and the result bytes cannot be extracted.","triggerScenarios":"A v1 module's view function returns an arbitrary JS object without `data`; SDK/host version skew changed the expected return shape; hand-implemented view bindings returning the wrong structure.","commonSituations":"Upgrading the module SDK or the host independently; copying view implementations across ABI versions; partially migrated codebases.","solutions":["Rebuild and republish the module with the SDK version matching the host.","Never hand-write __call_view_anon__ return values; use SDK-generated bindings.","Upgrade host and module together in lockstep.","If both are current, report the ABI mismatch with module and host versions."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"Catch view-call errors containing 'data key not found' and surface them as 'module/host ABI mismatch - republish the module with a matching SDK' rather than as app-level view errors.","preventionTips":["Pin module SDK and host versions together in CI.","Never bypass generated bindings for view functions.","Run a canary view call after every publish."],"tags":["view","v8","syscall","v1-abi","abi-mismatch"],"backgroundTag":"abi-contract-violation","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}