Effect CommunityEC
Effect Community2mo ago
1 reply
Kam

Accessing MySQL Error Fields in @effect/sql-mysql2

[13:12:21.983] ERROR (#0):
  SqlError: Failed to execute statement
      at /home...
...
      at addChunk (node:internal/streams/readable:368:12) {
    _tag: 'SqlError',
    [cause]: Error: Unknown column 'created_a' in 'field list'
        at Packet.asError (/home/kevin/camp/be/node_modules/mysql2/lib/packets/packet.js:740:17)
...
        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 'created_a' in 'field list'",
      sql: 'SELECT user_id, name, created_a FROM user WHERE user_id = ?'
    }
  }


This is an error from MySql (using the @effect/sql-mysql2 package).
I would like to transform that error in order to have all the
code
, sqlMessage, sql strings inside one message string of my custom SQLError type.
How do I access those fields in a usable way? I tried both Effect.mapError and Effect.mapErrorCause, and still can't find a way to access those fields.
Was this page helpful?