Effect CommunityEC
Effect Community10mo ago
14 replies
Kyrre Gjerstad

Help with Effect Error Handling

Hi everyone! I'm working on learning effect and creating a basic todo app (classic first project!). I'm using SqliteDrizzle for my database, but I'm struggling with error handling.

Current Issue


The current pattern works, but it's leaving out important details from the error. For example, my tapErrorCause only prints out this error:

Original DB Error (createTodo): (FiberFailure) SqlError: Failed to execute statement


But the original error contains much more useful information:

{
  [cause]: (FiberFailure) SqlError: Failed to execute statement
      at catch (/node_modules/@effect/sql-libsql/dist/esm/LibsqlClient.js:47:25)
      at file://node_modules/.pnpm/effect@3.14.3/node_modules/effect/dist/esm/internal/core-effect.js:563:51 {
    [cause]: LibsqlError: SQLITE_CONSTRAINT: SQLite error: FOREIGN KEY constraint failed
        at mapHranaError (file:///node_modules/.pnpm/@libsql+client@0.12.0/node_modules/@libsql/client/lib-esm/hrana.js:268:16)
        at file://node_modules/.pnpm/@libsql+client@0.12.0/node_modules/@libsql/client/lib-esm/http.js:76:23
        at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
      [cause]: ResponseError: SQLite error: FOREIGN KEY constraint failed
    }
  }
}


My Question


How can I create a better error mapping or in general handle the error but still get all the details from it? I'd like to be able to see the full error chain, especially the specific SQLite error (like "FOREIGN KEY constraint failed" in this case).

Code in comments since the discord post is too long.

Thanks in advance for any help!
Was this page helpful?