Effect CommunityEC
Effect Community2mo ago
1 reply
Kam

Accessing SqlError Details in Effect SQL Library

Errors from the effect sql library (mysql2, to be precise) have the following format. How to to get the sqlMessage , code, etc? I can't find any way to access them. I only see them when I print the error itself as a whole (with Effect.tap((e) => Effect.log(e))).

  SqlError: Failed to execute statement
      at /home/kevin/camp/be/node_modules/@effect/sql-mysql2/src/MysqlClient.ts:112:34
      at Prepare.onResult (/home/kevin/camp/be/node_modules/mysql2/lib/base/connection.js:682:11)
      at Prepare.execute (/home/kevin/camp/be/node_modules/mysql2/lib/commands/command.js:36:14)
      at PoolConnection.handlePacket (/home/kevin/camp/be/node_modules/mysql2/lib/base/connection.js:477:34)
      ... 5 lines matching cause stack trace ...
      at addChunk (node:internal/streams/readable:368:12) {
    _tag: 'SqlError',
    [cause]: Error: Unknown column 'c.doN' in 'where clause'
        at Packet.asError (/home/kevin/camp/be/node_modules/mysql2/lib/packets/packet.js:740:17)
        at Prepare.execute (/home/kevin/camp/be/node_modules/mysql2/lib/commands/command.js:29:26)
        at PoolConnection.handlePacket (/home/kevin/camp/be/node_modules/mysql2/lib/base/connection.js:477:34)
        at PacketParser.onPacket (/home/kevin/camp/be/node_modules/mysql2/lib/base/connection.js:93:12)
        at PacketParser.executeStart (/home/kevin/camp/be/node_modules/mysql2/lib/packet_parser.js:75:16)
        at Socket.<anonymous> (/home/kevin/camp/be/node_modules/mysql2/lib/base/connection.js:100:25)
        at Socket.emit (node:events:517:28)
        at Socket.emit (node:domain:489:12)
        at addChunk (node:internal/streams/readable:368:12)
        at readableAddChunk (node:internal/streams/readable:341:9) {
      code: 'ER_BAD_FIELD_ERROR',
      errno: 1054,
      sqlState: '42S22',
      sqlMessage: "Unknown column 'c.doN' in 'where clause'",
      sql: "SELECT count(*) FROM campsite c WHERE c.doN = '경기'"
    }
  }
Was this page helpful?