{"record":{"id":"80a6c18be349b6fc","repo":"lancedb/lancedb","slug":"expected-an-int-type-to-have-a-bitwidth-and-iss","errorCode":null,"errorMessage":"Expected an Int Type to have a `bitWidth` and `isSigned` property","messagePattern":"Expected an Int Type to have a `bitWidth` and `isSigned` property","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"nodejs/lancedb/sanitize.ts","lineNumber":124,"sourceCode":"  for (const [key, value] of entries) {\n    if (typeof key !== \"string\" || typeof value !== \"string\") {\n      throw Error(\n        \"Expected metadata, if present, to be a Map<string, string> but it had non-string keys or values\",\n      );\n    }\n    metadata.set(key, value);\n  }\n  return metadata;\n}\n\nexport function sanitizeInt(typeLike: object) {\n  if (\n    !(\"bitWidth\" in typeLike) ||\n    typeof typeLike.bitWidth !== \"number\" ||\n    !(\"isSigned\" in typeLike) ||\n    typeof typeLike.isSigned !== \"boolean\"\n  ) {\n    throw Error(\n      \"Expected an Int Type to have a `bitWidth` and `isSigned` property\",\n    );\n  }\n  return new Int(typeLike.isSigned, typeLike.bitWidth as IntBitWidth);\n}\n\nexport function sanitizeFloat(typeLike: object) {\n  if (!(\"precision\" in typeLike) || typeof typeLike.precision !== \"number\") {\n    throw Error(\"Expected a Float Type to have a `precision` property\");\n  }\n  return new Float(typeLike.precision as Precision);\n}\n\nexport function sanitizeDecimal(typeLike: object) {\n  if (\n    !(\"scale\" in typeLike) ||\n    typeof typeLike.scale !== \"number\" ||\n    !(\"precision\" in typeLike) ||","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/lancedb/lancedb/blob/c7b051aff7039333a3f61b79217246c27676806a/nodejs/lancedb/sanitize.ts#L106-L142","documentation":"sanitizeInt rebuilds an Arrow Int type from a plain object and requires `bitWidth` and `isSigned`. If the provided type-like object is missing or has wrongly typed values for these fields, it throws — the input was not a recognizable Arrow Int type.","triggerScenarios":"Passing a hand-built or partially deserialized type object (e.g. from JSON that dropped the Int properties) into schema sanitization.","commonSituations":"Serializing a schema to JSON and reconstructing it without preserving bitWidth/isSigned; using types from a mismatched apache-arrow version.","solutions":["Use actual apache-arrow type instances (new Int(true, 32), Int32, etc.) rather than plain objects","When round-tripping through JSON, preserve bitWidth and isSigned and restore them before use","Check that apache-arrow and lancedb versions are compatible"],"exampleFix":"// before\nconst t = { typeId: Type.Int };\n// after\nimport { Int } from 'apache-arrow';\nconst t = new Int(true, 32);","handlingStrategy":"type-guard","validationCode":"function looksLikeIntType(t) {\n  return t && typeof t.bitWidth === 'number' && typeof t.isSigned === 'boolean';\n}\nif (!looksLikeIntType(candidateType)) throw new Error('rebuild Int type with bitWidth/isSigned');","typeGuard":"const isIntLike = (t: unknown): t is { bitWidth: number; isSigned: boolean } =>\n  typeof t === 'object' && t !== null &&\n  'bitWidth' in t && typeof (t as any).bitWidth === 'number' &&\n  'isSigned' in t && typeof (t as any).isSigned === 'boolean';","tryCatchPattern":"try {\n  sanitized = sanitizeSchema(schema);\n} catch (e) {\n  if (String(e).includes('bitWidth')) {\n    // rebuild the field type with new Int(isSigned, bitWidth) and retry\n  } else throw e;\n}","preventionTips":["Use real apache-arrow Int instances, not plain objects","Preserve bitWidth/isSigned when serializing schemas through JSON","Pin compatible apache-arrow and lancedb versions"],"tags":["nodejs","arrow","schema","type-mismatch"],"backgroundTag":"invalid-argument-value","analyzedSha":"c7b051aff7039333a3f61b79217246c27676806a","analyzedAt":"2026-09-08T23:42:37.579Z","contentChangedAt":"2026-09-08T23:42:37.579Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}