Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Show instance of Effectful.Error.Static.ErrorWrapper #232

Merged
merged 1 commit into from
Aug 26, 2024

Conversation

arybczak
Copy link
Member

For example, if a third-party library spawns worker threads and if a job throws, it simply catches SomeException, logs it and retries the job later, as of today internal exceptions representing errors of the Error effect wouldn't show any info about the error, just the backtrace.

This fixes it at the cost of small API breakage.

TODO changelog

@arybczak arybczak force-pushed the showable-error branch 2 times, most recently from e9f5c5e to 491271a Compare August 10, 2024 10:28
@arybczak arybczak force-pushed the showable-error branch 3 times, most recently from 11c1d57 to e0b02ea Compare August 26, 2024 17:42
For example, if a third-party library spawns worker threads and if a job throws,
it simply catches SomeException, logs it and retries the job later, as of today
internal exceptions representing errors of the `Error` effect wouldn't show any
info about the error, just the backtrace.

This fixes it at the cost of small API breakage.
@arybczak arybczak merged commit bcafb9b into master Aug 26, 2024
7 checks passed
@arybczak arybczak deleted the showable-error branch August 26, 2024 17:48
@torgeirsh
Copy link

@arybczak Is there a way to avoid catching ErrorWrapper in such a scenario? There doesn't seen to be a predicate similar to isSyncException, and the type isn't exported for pattern matching. As a workaround, I'm parsing the output of show while ignoring the screaming voice at the back of my mind. :)

@arybczak
Copy link
Member Author

I'm parsing the output of show

Umm, that's bad. Why?

@torgeirsh
Copy link

Yes, like I said it's a workaround. Is there a better way?

@arybczak
Copy link
Member Author

Yeah, but why do you need to do that? I need to know the use case to suggest a solution (or improve the library).

@torgeirsh
Copy link

Oh right. It's a similar situation to the one you described, where an existing application catches SomeException for logging purposes, with the unfortunate side effect of intercepting Error effects. The least intrusive solution seems to be modifying the exception handler to catch "SomeException, except when it's an ErrorWrapper", similar to how catchSync works.

@arybczak
Copy link
Member Author

Hmm. I could in theory change ErrorWrapper to be marked as asynchronous exception (since it's an internal implementation detail), so it's not caught by catchAnySync, but I'm not sure if it's a good idea.

@torgeirsh
Copy link

I like the idea! It's a white lie, but benefits from existing awareness about the perils of catching asynchronous exceptions.

@ocharles
Copy link

One place where this is unfortunate is wrapping a Hedgehog effect. For things like failure, Hedgehog would normally use Left, so when we wrap that in effectful, it becomes a throw. However, Hedgehog also has evalM which uses try. But now in an effectful world if I surround a block of code that uses failure with evalM I lose the accurate stack trace at the point of failure and instead get a stack trace at the point of evalM! Even worse is it uses the show instance for the exception, which now talks about this mysterious ErrorWrapper. Plain hedgehog has none of this, and would simple report from the location of failure. It's the very general try in evalM that is the problem and I can't really see an alternative, but it is an unfortunate wart I get when I try and lift Hedgehog's Test into effectful

@arybczak
Copy link
Member Author

Ok, I created #283. I'll let it sit for a while and think if this change has a potential to blow up in our faces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants