Effect-TS / effect

An ecosystem of tools to build robust applications in TypeScript.

Home Page:https://effect.website

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

From Discord: Handling Missing 'cause' in @effect/schema Exceptions

effect-bot opened this issue · comments

Summary

The discussion revolves around identifying exceptions generated by @effect/schema when using its functionality, particularly when some exceptions do not include a cause property, which would ideally contain the parse issue. Here are the key points and takeaways from the conversation:

  1. Issue with cause Property: The initial problem highlighted is that not all errors thrown by @effect/schema operations, such as decodeSync, include a cause property. This property is crucial for understanding the underlying issue when an error occurs, especially when working with a top-level error boundary to catch unhandled exceptions.

  2. Example of Missing cause: A specific example was provided where calling S.decodeSync(S.String)(42) results in an error without a cause, making it challenging to detect and handle errors specific to @effect/schema.

  3. Advice on Error Handling: It was suggested to use decode instead of decodeSync for fully typed errors, indicating that decode might provide more detailed error information, including the cause.

  4. Version Update Recommendation: To address the issue with missing cause properties, upgrading to the latest version of the library (version 0.67 at the time of the conversation) was recommended. This version presumably includes improvements to error handling, ensuring that more, if not all, errors include a cause.

  5. Acknowledgment of Oversight: It was acknowledged that the absence of a cause in errors thrown by asserts is an oversight, with a commitment to fix this issue. However, it was also mentioned that errors from operations like decodeSync should already have the cause covered in the mentioned version.

Key Takeaways:

  • Upgrading to the latest version of @effect/schema is crucial for better error handling and to ensure errors include a cause where expected.
  • Using decode over decodeSync might offer more detailed and fully typed errors, beneficial for debugging and error handling.
  • The library maintainers are aware of the issues regarding error handling and are committed to making improvements, indicating ongoing support and development of the library.

Discord thread

https://discord.com/channels/795981131316985866/1238873888889372802