Effect CommunityEC
Effect Community2y ago
9 replies
mkrause

Handling Missing 'cause' in @effect/schema Exceptions

I'm looking for a way to detect if a given exception is one produced by
@effect/schema
. The exceptions I've seen are all instances of the generic base Error. I searched the code and found that many places will assign a cause with the parse
issue
, so I can use that. However, not all errors have a cause. For example:

import { Schema as S } from '@effect/schema';

try {
  S.decodeSync(S.String)(42);
} catch (error) {
  console.log(error.cause); // Logs `undefined`
}


I'm guessing this is an oversight? Found one case here that's missing the cause (not sure if it's the one causing the example above):

https://github.com/Effect-TS/effect/blob/423dd38c1c634a44e084c0de9ddd9f1b92aa4617/packages/schema/src/ParseResult.ts#L734
Was this page helpful?