{"record":{"id":"1ed6b2d50d8edac1","repo":"tursodatabase/turso","slug":"expected-first-argument-to-be-an-array-of-statemen-1ed6b2","errorCode":null,"errorMessage":"Expected first argument to be an array of statements","messagePattern":"Expected first argument to be an array of statements","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"serverless/javascript/src/compat.ts","lineNumber":339,"sourceCode":"    } catch (error: any) {\n      if (error instanceof LibsqlError) {\n        throw error;\n      }\n      throw mapDatabaseError(error, \"EXECUTE_ERROR\");\n    } finally {\n      this.execLock.release();\n    }\n  }\n\n  async batch(stmts: Array<InStatement>, options?: TransactionMode | BatchOptions): Promise<Array<BatchResultSet>> {\n    await this.execLock.acquire();\n    try {\n      if (this._closed) {\n        throw new LibsqlError(\"Client is closed\", \"CLIENT_CLOSED\");\n      }\n\n      if (!Array.isArray(stmts)) {\n        throw new TypeError(\"Expected first argument to be an array of statements\");\n      }\n\n      const { mode, raw } = this.normalizeBatchOptions(options);\n      const batchMode = mode ?? \"deferred\";\n\n      const results = await this.session.batch(\n        stmts,\n        batchMode,\n        undefined,\n        this._defaultSafeIntegers,\n        raw,\n      );\n\n      return results.map((result: any) => this.convertBatchResult(result));\n    } catch (error: any) {\n      if (error instanceof LibsqlError) {\n        throw error;\n      }","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/tursodatabase/turso/blob/6c7252267988c76e632af00a671e4b9788dfae13/serverless/javascript/src/compat.ts#L321-L357","documentation":"batch() requires its first argument to be an array of InStatement; anything else - a single statement object, a bare string, varargs, or undefined - throws this TypeError. Note the throw happens inside batch()'s try block, so the compat layer's catch wraps it into a BATCH_ERROR LibsqlError with the TypeError as the cause; the message still tells you the shape of the argument was wrong.","triggerScenarios":"client.batch(stmt) with a single statement instead of client.batch([stmt]); calling batch(s1, s2) as if it were variadic; passing a value that is undefined because a builder function forgot to return its array.","commonSituations":"Porting code from an API that took varargs or a single statement; conditional statement lists where the array variable ends up undefined; refactors that return undefined from a statements-builder helper.","solutions":["Always pass an array: client.batch([stmt1, stmt2]) or client.batch([sqlString])","For a single statement, use client.execute(stmt) instead","Check Array.isArray(stmts) before calling batch in code that assembles statements dynamically","Inspect error.cause if you caught a BATCH_ERROR - the TypeError inside identifies this case"],"exampleFix":"// before\nawait client.batch({ sql: 'UPDATE t SET x = 1' }); // not an array\nawait client.batch(stmt1, stmt2);               // varargs are not supported\n\n// after\nawait client.batch([{ sql: 'UPDATE t SET x = 1' }]);\nawait client.batch([stmt1, stmt2]);","handlingStrategy":"validation","validationCode":"function toBatchArg(stmts: InStatement | InStatement[] | undefined): InStatement[] {\n  if (stmts === undefined) return [];\n  return Array.isArray(stmts) ? stmts : [stmts];\n}\nawait client.batch(toBatchArg(maybeSingleStmt));","typeGuard":"function isStatementArray(v: unknown): v is Array<InStatement> {\n  return Array.isArray(v);\n}","tryCatchPattern":null,"preventionTips":["batch() takes exactly one array argument - no varargs","Use execute() for single statements","When a builder assembles statements dynamically, default its return value to an array"],"tags":["serverless","batch","argument-validation","libsql-compat","typeerror"],"backgroundTag":"invalid-argument-value","analyzedSha":"6c7252267988c76e632af00a671e4b9788dfae13","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}