{"record":{"id":"4affd07c9b1c26e9","repo":"clockworklabs/SpacetimeDB","slug":"data-key-not-found-in-return-object-4affd0","errorCode":null,"errorMessage":"data key not found in return object","messagePattern":"data key not found in return object","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/core/src/host/v8/syscall/v2.rs","lineNumber":556,"sourceCode":"        args: view_args,\n    } = op;\n    // Serialize the arguments.\n    let view_id = serialize_to_js(scope, &view_id)?;\n    let sender = serialize_to_js(scope, &sender.to_u256())?;\n    let view_args = serialize_to_js(scope, view_args.get_bsatn())?;\n    let args = &[view_id, sender, view_args];\n\n    // Call the function.\n    let ret = call_recv_fun(scope, fun, hooks.recv, args)?;\n\n    // 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":538,"sourceCodeEnd":574,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/core/src/host/v8/syscall/v2.rs#L538-L574","documentation":"For ABI-v2 view calls the host expects __call_view_anon__ to return an object with a `data` field containing a Uint8Array of encoded rows. This error means the object came back without a readable `data` property — an envelope-shape mismatch between the module's v2 bindings and the host's protocol. The view may have run fine; its result simply cannot be decoded.","triggerScenarios":"The v2 view wrapper returns an object lacking `data`: bindings generated for a different ABI or host version than deployed, a custom override of __call_view_anon__ returning a different envelope, or mixed old/new bundle code after an upgrade.","commonSituations":"Upgrading the host without regenerating JS bindings; forking or wrapping generated view entry points; serving stale bundles from caches after a republish.","solutions":["Regenerate the JS bindings for the deployed host/ABI version and republish the module.","Keep the returned envelope exactly `{ data: Uint8Array }` in any custom wrapper.","Verify the deployed bundle actually contains the regenerated wrapper (bust caches).","Pin host and bindings versions together in CI so they cannot drift."],"exampleFix":"// before: v2 wrapper returns rows under a different key\nreturn { rows: encoded };\n\n// after: v2 envelope with the `data` field\nreturn { data: encoded };","handlingStrategy":"validation","validationCode":"// v2 envelope check in bindings tests\nconst out = await callViewAnon(viewId, args);\nif (!(out && out.data instanceof Uint8Array)) {\n    throw new Error('v2 view call must return { data: Uint8Array }');\n}","typeGuard":"function isV2ViewEnvelope(v: unknown): v is { data: Uint8Array } {\n  return typeof v === 'object' && v !== null && (v as any).data instanceof Uint8Array;\n}","tryCatchPattern":null,"preventionTips":["Pin host and bindings versions together in CI.","Keep the returned envelope exactly { data: Uint8Array } in custom wrappers.","Verify the deployed bundle contains the regenerated wrapper after upgrades."],"tags":["v8","views","abi-v2","bindings-mismatch"],"backgroundTag":"response-shape-mismatch","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}