-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
exception data lost in multi-threaded environment #884
Comments
@jeroenvandijk This is related to this: https://github.com/babashka/sci/blame/master/src/sci/impl/utils.cljc#L97 I'll see if there is a better solution. I'm probably going to rewrite some of the error / stack logic soon, as part of #871. |
TBH, I don't recall why I did this. Perhaps some thread-unsafety.. but I don't see any failing tests. I'll think some more and then will remove the |
Ah I'm happy you were able to already identify the cause. I've been staring at the code to see if I could find it, but had no idea. |
@jeroenvandijk Hmm, I think I found the reason for this change. When I remove this check, I get a failing library test in bb:
|
I reverted this solution, but will try to find another one. |
Note to self: Repro:
This should print: |
Smaller repro:
This should print |
@jeroenvandijk You can preserve location information in futures now with: #?(:clj
(deftest thread-test
(let [invoke-ex-fn
(fn [f]
(try
(f)
(catch Throwable e
(ex-data e))))]
(let [f (sci.core/eval-string "(fn [] (try (/ 1 0) (catch ^:sci/error Exception e (throw e))))")]
(is (let [res @(future (invoke-ex-fn f))]
(is (= {:line 1 :column 13} (select-keys res [:line :column]))))))))) So wrap your function in a try/catch and catch the exception with |
@borkdude Very cool, thank you! I will play around with it. FYI, I am not using future specifically, but it was an easy way to reproduce the multithreaded scenario. I believe that what you are suggesting will work for me though! Thanks again! |
Yes, it will work regardless of |
I need to do more further testing, but by wrapping the body of my external macros in a (sci/eval-string "..."
{:bindings
{'with-sci-error (sci/eval-string "(fn [f] (try (f) (catch ^:sci/error Exception ex (throw ex))))")}}) |
version
org.babashka/sci 0.7.39 (and older)
platform
JVM
problem
Exception data is lost* when a function that was created in another thread is invoked and throws.
(*) most importantly the parts of
ex-data
that hold the:line
and:column
data of the relevant sci code.repro
expected behavior
I need the error information to display a more helpful error message (like in Babashka with a line pointing to the problematic code). When the problematic code was invoked from a different thread this doesn't work. I'm using Sci in a multithreaded environment (a web server) so I've seen this scenario frequently now. It took me some time to identify it.
(Sponsor, though nothing blocking, but definitely nice to have)
The text was updated successfully, but these errors were encountered: