hyperfiddle

Dustin Getz (Hyperfiddle) 2025-03-05T11:56:21.772729Z

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

👍 8
❤️ 7
⚡ 6
oλv 2025-03-05T16:14:27.099549Z

How should I handle failures when using e/Task?

oλv 2025-03-05T16:26:53.285819Z

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)))))

xificurC 2025-03-05T16:41:39.272509Z

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

oλv 2025-03-05T18:41:15.449209Z

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?

oλv 2025-03-05T18:43:23.995919Z

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"))))

xificurC 2025-03-05T20:15:04.767379Z

We could support it, our APIs are largely need-driven. And yes, in v2 you could solve this with try catch

👍 1