{"record":{"id":"139d8c6aa32b68e7","repo":"denoland/deno","slug":"cannot-get-pointer-size-unsupported-type-type","errorCode":null,"errorMessage":"Cannot get pointer size, unsupported type: ${type}","messagePattern":"Cannot get pointer size, unsupported type: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/ffi/00_ffi.js","lineNumber":390,"sourceCode":"      return [1, 1];\n    case \"u16\":\n    case \"i16\":\n      return [2, 2];\n    case \"u32\":\n    case \"i32\":\n    case \"f32\":\n      return [4, 4];\n    case \"u64\":\n    case \"i64\":\n    case \"f64\":\n    case \"pointer\":\n    case \"buffer\":\n    case \"function\":\n    case \"usize\":\n    case \"isize\":\n      return [8, 8];\n    default:\n      throw new TypeError(`Cannot get pointer size, unsupported type: ${type}`);\n  }\n}\n\nclass UnsafeCallback {\n  #refcount;\n  // Internal promise only meant to keep Deno from exiting\n  #refpromise;\n  #rid;\n  definition;\n  callback;\n  pointer;\n\n  constructor(definition, callback) {\n    if (definition.nonblocking) {\n      throw new TypeError(\n        \"Cannot construct UnsafeCallback: cannot be nonblocking\",\n      );\n    }","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/ffi/00_ffi.js#L372-L408","documentation":"When FFI needs the size/alignment of a type (for example struct layout in UnsafeFnPointer), getTypeSizeAndAlignment switches over the supported scalar names: fixed-width integers (u8/u16/u32/u64, i8/i16/i32/i64), floats (f32/f64), and 8-byte types (pointer, buffer, function, usize, isize), plus struct objects. An unrecognized string reaches the default arm and throws a TypeError echoing the offending type.","triggerScenarios":"A typo in a type name (\"unit8\", \"int\", \"float\", \"char\", \"size_t\"), passing a JS value instead of a type-name string, or a nested struct field using a C-style name anywhere a size must be computed.","commonSituations":"Hand-porting C headers and keeping C type names instead of the FFI vocabulary; generated bindings with unmapped typedefs; renames between Deno versions (older code using \"usize\"/\"isize\" variants).","solutions":["Map C names to FFI names: size_t/uintptr_t -> \"usize\", char* -> \"pointer\", float -> \"f32\", double -> \"f64\"","Use only the supported set: u8/u16/u32/u64, i8/i16/i32/i64, f32/f64, usize/isize, pointer, buffer, function, or { struct: [...] }","Find the exact bad string from the error message and grep your type definitions for it"],"exampleFix":"// before\nconst def = { parameters: [\"size_t\"], result: \"void\" }; // unsupported type: size_t\n\n// after\nconst def = { parameters: [\"usize\"], result: \"void\" };","handlingStrategy":"type-guard","validationCode":"const FFI_SCALARS = new Set([\"u8\",\"u16\",\"u32\",\"u64\",\"i8\",\"i16\",\"i32\",\"i64\",\"f32\",\"f64\",\"usize\",\"isize\",\"pointer\",\"buffer\",\"function\",\"void\"]);\nfunction assertValidTypes(t, path = \"root\") {\n  if (typeof t === \"string\") {\n    if (!FFI_SCALARS.has(t)) throw new Error(`invalid FFI type '${t}' at ${path}`);\n  } else if (t && typeof t === \"object\" && Array.isArray(t.struct)) {\n    t.struct.forEach((f, i) => assertValidTypes(f, `${path}.struct[${i}]`));\n  } else {\n    throw new Error(`invalid FFI type node at ${path}`);\n  }\n}","typeGuard":"const FFI_SCALARS = new Set([\"u8\",\"u16\",\"u32\",\"u64\",\"i8\",\"i16\",\"i32\",\"i64\",\"f32\",\"f64\",\"usize\",\"isize\",\"pointer\",\"buffer\",\"function\",\"void\"]);\nfunction isFfiTypeNode(t: unknown): boolean {\n  if (typeof t === \"string\") return FFI_SCALARS.has(t);\n  return typeof t === \"object\" && t !== null && Array.isArray((t as { struct?: unknown[] }).struct);\n}","tryCatchPattern":"try {\n  const fn = new Deno.UnsafeFnPointer(ptr, definition);\n} catch (err) {\n  if (err instanceof TypeError && err.message.startsWith(\"Cannot get pointer size, unsupported type:\")) {\n    // the bad type name is printed after the colon; fix it to an FFI scalar or struct\n  } else throw err;\n}","preventionTips":["Map C names once in a table: size_t->usize, char*->pointer, float->f32, double->f64","Validate type trees from generated bindings before dlopen/use","The error message names the offending type string — search your definitions for it"],"tags":["ffi","types","struct","layout"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}