{"record":{"id":"2a2c15a799a39dbc","repo":"denoland/deno","slug":"cannot-access-pointer-expected-arraybuffer-sh","errorCode":null,"errorMessage":"Cannot access pointer: expected 'ArrayBuffer', 'SharedArrayBuffer', 'ArrayBufferView' or 'UnsafeCallbackPrototype', received ${typeof value}","messagePattern":"Cannot access pointer: expected 'ArrayBuffer', 'SharedArrayBuffer', 'ArrayBufferView' or 'UnsafeCallbackPrototype', received (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/ffi/00_ffi.js","lineNumber":258,"sourceCode":"    let pointer;\n    if (ArrayBufferIsView(value)) {\n      if (value.length === 0) {\n        pointer = op_ffi_ptr_of_exact(value);\n      } else {\n        pointer = op_ffi_ptr_of(value);\n      }\n    } else if (isAnyArrayBuffer(value)) {\n      // `ArrayBuffer`/`SharedArrayBuffer` expose `byteLength`, not `length`, so\n      // wrap in a `Uint8Array` and measure that to detect the empty case (the\n      // `op`s require a view anyway).\n      const view = new Uint8Array(value);\n      if (TypedArrayPrototypeGetByteLength(view) === 0) {\n        pointer = op_ffi_ptr_of_exact(view);\n      } else {\n        pointer = op_ffi_ptr_of(view);\n      }\n    } else {\n      throw new TypeError(\n        `Cannot access pointer: expected 'ArrayBuffer', 'SharedArrayBuffer', 'ArrayBufferView' or 'UnsafeCallbackPrototype', received ${typeof value}`,\n      );\n    }\n    if (pointer) {\n      POINTER_TO_BUFFER_WEAK_MAP.set(pointer, value);\n    }\n    return pointer;\n  }\n\n  static offset(value, offset) {\n    return op_ffi_ptr_offset(value, offset);\n  }\n\n  static value(value) {\n    if (ObjectPrototypeIsPrototypeOf(UnsafeCallbackPrototype, value)) {\n      value = value.pointer;\n    }\n    return op_ffi_ptr_value(value);","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/ffi/00_ffi.js#L240-L276","documentation":"Deno.UnsafePointer.of(value) extracts the memory address of a buffer-like value. It accepts an UnsafeCallback (returning its stored pointer), any ArrayBufferView (TypedArray/DataView, pointing at the first byte), or an ArrayBuffer/SharedArrayBuffer (wrapped in a Uint8Array internally). Any other input has no address to take, so a TypeError reporting the received typeof is thrown.","triggerScenarios":"Passing a bigint or number holding a pointer value, a plain object, a string, null, or undefined to Deno.UnsafePointer.of(); also passing a Deno.UnsafePointerView instead of its underlying buffer.","commonSituations":"Confusing UnsafePointer.of (buffer to pointer) with UnsafePointer.create (bigint to pointer object); round-tripping a pointer value back through of(); passing a Web API object (Blob, Response) that is not backed by a contiguous buffer.","solutions":["For numeric addresses use Deno.UnsafePointer.create(0xn) instead of of()","Wrap your data in a TypedArray before calling of(): Deno.UnsafePointer.of(new Uint8Array(buf))","For UnsafeCallback instances pass the callback object itself (of() returns cb.pointer), never cb.pointer (a bigint)"],"exampleFix":"// before\nconst ptr = Deno.UnsafePointer.of(someBigintPointer); // TypeError\n\n// after\nconst ptrObj = Deno.UnsafePointer.create(someBigintPointer);\n// or, to get the address of actual bytes:\nconst ptrOfData = Deno.UnsafePointer.of(new Uint8Array(data));","handlingStrategy":"type-guard","validationCode":"function isPointerSource(value) {\n  return value instanceof ArrayBuffer || value instanceof SharedArrayBuffer ||\n    ArrayBuffer.isView(value) ||\n    (typeof value === \"object\" && value !== null && \"pointer\" in value && \"definition\" in value);\n}","typeGuard":"function isPointerSource(\n  value: unknown,\n): value is ArrayBuffer | SharedArrayBuffer | ArrayBufferView | Deno.UnsafeCallback {\n  return value instanceof ArrayBuffer || value instanceof SharedArrayBuffer ||\n    ArrayBuffer.isView(value as ArrayBufferView) ||\n    (typeof value === \"object\" && value !== null &&\n      \"pointer\" in (value as object) && \"definition\" in (value as object));\n}","tryCatchPattern":"try {\n  const ptr = Deno.UnsafePointer.of(value);\n} catch (err) {\n  if (err instanceof TypeError && err.message.startsWith(\"Cannot access pointer\")) {\n    // value has no address: wrap bytes in a TypedArray, or use UnsafePointer.create for numeric addresses\n  } else throw err;\n}","preventionTips":["Use UnsafePointer.create(bigint) for numeric addresses and of(buffer) for real buffers","Keep a tiny wrapper that dispatches on the input kind so call sites cannot mix them up","Pass UnsafeCallback objects directly; never their .pointer bigint","Type FFI helper parameters precisely (DataView/TypedArray, not unknown)"],"tags":["ffi","pointer","type-error","buffer"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}