{"record":{"id":"fc543e95c2ce1f80","repo":"tursodatabase/turso","slug":"expected-second-argument-to-be-an-options-object","errorCode":null,"errorMessage":"Expected second argument to be an options object","messagePattern":"Expected second argument to be an options object","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"bindings/javascript/packages/common/compat.ts","lineNumber":216,"sourceCode":"      immediate: { value: wrapTxn(\"IMMEDIATE\") },\n      exclusive: { value: wrapTxn(\"EXCLUSIVE\") },\n      database: { value: this, enumerable: true },\n    };\n    Object.defineProperties(properties.default.value, properties);\n    Object.defineProperties(properties.deferred.value, properties);\n    Object.defineProperties(properties.immediate.value, properties);\n    Object.defineProperties(properties.exclusive.value, properties);\n    return properties.default.value;\n  }\n\n  pragma(source, options) {\n    if (options == null) options = {};\n\n    if (typeof source !== \"string\")\n      throw new TypeError(\"Expected first argument to be a string\");\n\n    if (typeof options !== \"object\")\n      throw new TypeError(\"Expected second argument to be an options object\");\n\n    const pragma = `PRAGMA ${source}`;\n\n    const stmt = this.prepare(pragma);\n    try {\n      const results = stmt.all();\n      return results;\n    } finally {\n      stmt.close();\n    }\n  }\n\n  backup(filename, options) {\n    throw new Error(\"not implemented\");\n  }\n\n  serialize(options) {\n    throw new Error(\"not implemented\");","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/bindings/javascript/packages/common/compat.ts#L198-L234","documentation":"Thrown by Database.pragma() when the second argument is present, non-null, and not an object. The method first normalizes null/undefined to {}, so this TypeError only fires for real non-object values such as strings, numbers, booleans, or functions passed as the options parameter.","triggerScenarios":"Calling db.pragma('journal_mode', 'WAL') (passing the value as the second argument instead of embedding it in the pragma string); passing a number or boolean; passing a function. Arrays technically pass since typeof [] === 'object', but strings and primitives do not.","commonSituations":"Misreading the API and trying to set a pragma value positionally (db.pragma('user_version', 2)); copy-pasting examples from a different SQLite wrapper whose pragma signature is (name, value); refactoring where an options object got replaced by one of its fields.","solutions":["Embed the value in the pragma string: db.pragma('user_version = 2') instead of db.pragma('user_version', 2)","If you genuinely need options, pass an object: db.pragma('journal_mode', { simple: true })","Omit the second argument entirely when no options are needed"],"exampleFix":"// before\ndb.pragma('user_version', 2); // number as 2nd arg -> TypeError\n\n// after\ndb.pragma('user_version = 2'); // assignment inside the pragma string","handlingStrategy":"validation","validationCode":"if (options !== undefined && options !== null && typeof options !== 'object') {\n  throw new TypeError(`pragma options must be an object, got ${typeof options}`);\n}\nreturn db.pragma(source, options);","typeGuard":"function isPragmaOptions(value: unknown): value is Record<string, unknown> {\n  return value == null || (typeof value === 'object' && !Array.isArray(value));\n}","tryCatchPattern":null,"preventionTips":["Set pragma values inside the string: db.pragma('journal_mode = WAL')","Never pass a primitive as the second argument","Type the parameter in TypeScript as `options?: object` so the compiler catches it first"],"tags":["turso","javascript","pragma","input-validation","better-sqlite3-compat"],"backgroundTag":"invalid-argument-type","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}