effect icon indicating copy to clipboard operation
effect copied to clipboard

From Discord: Improving Internal Functionality: Limited Access to TagProto and prettyErrors

Open effect-bot opened this issue 2 years ago • 1 comments

Summary

The discussion revolves around two topics: exposing prettyErrors and the usage of TagProto.

Regarding prettyErrors, it is suggested to expose it to improve internal functionality. However, no specific details are provided about how it should be exposed or what improvements it would bring.

As for TagProto, there is a question about its necessity and the possibility of approaching the functionality differently. It is suggested to have an abstract class called Taggable that would provide similar functionality as TagClass.

Key takeaways:

  • Exposing prettyErrors could potentially improve internal functionality, but more details are needed to understand the specific improvements it would bring.
  • The necessity of TagProto is questioned, and an alternative approach using an abstract class called Taggable is suggested.

Example article

Improving Internal Functionality: Limited Access to TagProto and prettyErrors

In the Effect-TS ecosystem, there are two internal functionalities that can be improved: limited access to TagProto and exposing prettyErrors. Let's discuss each of these functionalities in detail.

Limited Access to TagProto

The TagProto is a helper class that allows a class to behave like a Tag. However, there is a need to limit access to TagProto and find an alternative approach. One possible solution is to introduce an abstract class called Taggable that provides the necessary functionality. This abstract class can be similar to existing classes like Streamable and Effectable.

Here's an example of how the Taggable abstract class can be implemented:

abstract class Taggable {
  abstract readonly _tag: string;
}

class MyTaggable extends Taggable {
  readonly _tag = "MyTag";
}

const taggable: Taggable = new MyTaggable();
console.log(taggable._tag); // Output: "MyTag"

By using the Taggable abstract class, we can achieve the desired functionality without exposing TagProto directly.

Exposing prettyErrors

Another improvement that can be made is exposing the prettyErrors functionality. Currently, prettyErrors is an internal functionality that provides a more readable and user-friendly error message. By exposing this functionality, users can benefit from enhanced error messages.

Here's an example of how prettyErrors can be used:

import { prettyErrors } from '@effect/io';

try {
  // Some code that throws an error
} catch (error) {
  console.log(prettyErrors(error));
}

The prettyErrors function takes an error object as input and returns a formatted error message. This can be extremely helpful during debugging and error handling.

By exposing prettyErrors, users can easily improve the error handling experience within their applications.

Conclusion

In this article, we discussed two internal functionalities that can be improved in the Effect-TS ecosystem: limited access to TagProto and exposing prettyErrors. By introducing the Taggable abstract class and exposing prettyErrors, users can have better control over their code and benefit from enhanced error messages. These improvements will contribute to a more robust and user-friendly development experience with Effect-TS.

Discord thread

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

effect-bot avatar Oct 04 '23 10:10 effect-bot

makeFiberFailure basically does what I was using prettyErrors for (get head for name/message/stack), so my case is kinda solved.

patroza avatar Oct 16 '23 09:10 patroza