You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've finished adapting @IGJoshua’s library Farolero to babashka (PR), but I thought I'd ask for a bit of advice before we merge.
In Clojure, Farolero relies on a custom java class extending Error (Signal.java) to hold additional data and skip the runtime cost of building a stack trace.
In Clojurescript, it relies on a record ((defrecord Signal ...)) as javascript allows throwing any object.
Neither of these solutions exist in Babashka: we can't use a custom java class nor can we throw anything as it has to be an instance of Error or an instance of a subclass of Error. The solution Joshua came up with and I implemented is to use the same record from Clojurescript, and then attach it to an ExceptionInfo as the data and use that as the cause for an instance of java.lang.Error. This allows us to catch all Errors and only rethrow if (some-> ex ex-cause ex-data) doesn't implement the correct protocol.
The big issue is one of speed: we're creating an ExceptionInfo (with associated stack trace) and then we're creating an Error (with associated stack trace). That's a lot of extra work to be immediately thrown away when the exception is caught.
Are there any ways around the extra work of creating these stack traces in Babashka or creating custom Error classes?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I've finished adapting @IGJoshua’s library Farolero to babashka (PR), but I thought I'd ask for a bit of advice before we merge.
In Clojure, Farolero relies on a custom java class extending Error (Signal.java) to hold additional data and skip the runtime cost of building a stack trace.
In Clojurescript, it relies on a record (
(defrecord Signal ...)
) as javascript allows throwing any object.Neither of these solutions exist in Babashka: we can't use a custom java class nor can we throw anything as it has to be an instance of Error or an instance of a subclass of Error. The solution Joshua came up with and I implemented is to use the same record from Clojurescript, and then attach it to an
ExceptionInfo
as the data and use that as the cause for an instance ofjava.lang.Error
. This allows us to catch all Errors and only rethrow if(some-> ex ex-cause ex-data)
doesn't implement the correct protocol.The big issue is one of speed: we're creating an
ExceptionInfo
(with associated stack trace) and then we're creating anError
(with associated stack trace). That's a lot of extra work to be immediately thrown away when the exception is caught.Are there any ways around the extra work of creating these stack traces in Babashka or creating custom Error classes?
Beta Was this translation helpful? Give feedback.
All reactions