High fidelity optimistic updates with correct busy and retry states - compare to the behavior of Apple's iMessage native app when SMS fails to go through
How should I handle failures when using e/Task?
iirc try/catch is not to be used in Electric
I’m doing (m-fail-with-success-value (similarity-search embedding) nil) where m-fail-with-success-value is a utility which takes a task and teaches it to handle failure by calling its success callback with the second argument (e.g nil or :error). This feels like hack, but it works:
(if-let [res (e/server (e/Task (m-fail-with-success-value t nil)))]
(do (dom/b (dom/text "Here's your result")) (Result res))
(dom/text "Something went wrong"))
(defn m-fail-with-success-value [task failure-value]
(fn [success failure]
(task success (fn [_] (success failure-value)))))I don't see anything wrong with your approach. I'd personally keep the failure value around so that I can decide what to do with it
To me it feels weird that the API for consuming Missionary tasks from Electric does not have the innate ability to support both callbacks. I’m guessing long term this hole will be filled by try/`catch` support?
I think I’ll conjure a a macro like
(Task t
<success-symbol> <success-body>
<failure-symbol> <failure-body>)
for my own use. This feels good to me at least:
(Task (similarity-search inp)
res (do (dom/b (dom/text "Here's your result")) (Result res))
err (do (t/error! err) (dom/b (dom/text "Something went wrong"))))We could support it, our APIs are largely need-driven. And yes, in v2 you could solve this with try catch