-
Notifications
You must be signed in to change notification settings - Fork 29
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
requirements for cancellation errors #51
Comments
Another possibility to consider if using errors for cancellation but still not wanting to lose the message is a stackless exception |
Yes, IMO the stacktrace is never useful so we can use that trick (singleton or not). Do you have a use case in mind where the cancellation error should have a payload or a specific message, which would disqualify the singleton approach ? In my experience, when a process is cancelled the error can be propagated from a deeply nested process so the specificity of the message is not really meaningful, I would find it less confusing to read a more generic message such as "Process cancelled." |
@bsless BTW any reason why overriding |
You might want specific cancelation errors to know exactly where or what got canceled. |
Well if you need to subclass However I'm not sure there's a need for subclassing. |
Additional thoughts :
So it's pretty clear that cancellation errors should have a dedicated class, but now what about the class hierarchy ? In my experience, cancelled status is different enough from other errors to not inherit The plan would be :
|
Not sure if this is relevant to this issue: I have found it pretty difficult to reliably determine whether an thrown exception was due to a task being cancelled or due to a real exceptional circumstance. For example, if a thread is cancelled it throws an java.lang.InterruptedException:
When datomic is interrupted, it throws an ExceptionInfo, and you have to check the ex-causes for the actual interruped exception. Would this proposal include wrapping InterruptedException (and other similar exceptions)? I've been using the following code to determine whether an exception is caused by cancellation:
|
After more thinking, this is overengineering. Clojure has good support for classes, better expose the class with a public constructor and check with @mjmeintjes thank you for raising this concern. I'm not interested in solving the "catch everything that could be an interruption" problem, because :
I think it's fine to expect the user to solve this on a case-by-case basis. If consistency is required, writing an adapter is easy enough : (require '[missionary.core :as m])
(import missionary.Cancelled)
(def sleeper
(m/via m/blk
(try (Thread/sleep 2000)
(catch InterruptedException e
(throw (Cancelled. (.getMessage e)))))))
(def datomic
(m/via m/blk
(try (d/q '[,,,])
(catch ExceptionInfo e
(throw (if (ex-cancelled? e)
(Cancelled. (.getMessage e)) e)))))) |
Fixed in |
Currently when a process is cancelled before termination it throws a new instance of
ExceptionInfo
with an entry for key:cancelled
. Two problems :The only requirement of the cancellation error is to be able to disambiguate it from other errors. A singleton would be a better fit - no runtime costs, fast checking based on identity.
The singleton is immutable and can be exposed :
Checking could be made easier with simple sugar :
The text was updated successfully, but these errors were encountered: