cljs-dev

Harold 2026-01-21T01:15:40.181499Z

A potentially interesting case to test:

async function quux() {
  throw "quux failed"
  return "unlucky"
}

async function go() {
  try {
    let x = await quux()
    console.log("finished!", x)
  } catch {
    console.log("caught around await!")
  }
}

go()
This pattern of using try/catch around await is common, I think, and the catch code runs even though the error was thrown inside the promise. On my computer in node this program prints "caught around await!" cljs users may have a similar expectation about how try, await, catch would interact.

borkdude 2026-01-21T07:05:59.616239Z

I think the test suite already tests this

Harold 2026-01-21T12:53:33.443119Z

I saw this test: https://github.com/clojure/clojurescript/pull/303/files#diff-0ace430754068ef427130bf7b8b9be4e5166f7d1eee8bdc90d9ec28a268732edR126-R136 and I may be misreading it, but await-in-throw isn't the same as throw-in-await. Perhaps there's another test I overlooked?

borkdude 2026-01-21T13:04:10.897749Z

I'm pretty sure that variation is going to work, but I can add it later. I guess I can replace (prn should not reach here) with (is false) as a better "should not reach here" as well.

👍 1
borkdude 2026-01-21T16:26:36.497699Z

I'll combine it with any other comments @dnolen might have

borkdude 2026-01-24T10:35:25.718479Z

@hhausman this test would do it right?

(deftest throw-in-await-test
  (async done
    (let [f (^:async fn [x] (throw "dude") x)]
      (try
        (let [_ (await (f 2))]
          (is false))
        (catch :default e
          (is (= "dude" e)))
        (finally (done))))))

borkdude 2026-01-24T10:38:33.617119Z

We already had this test more or less in this one:

(deftest await-in-throw-test
  (async done
    (let [f (^:async fn [x] (inc (if (odd? x) (throw (await (js/Promise.resolve "dude"))) x)))]
      (try
        (let [x (await (f 2))]
          (is (= 3 x)))
        (let [x (try (await (f 1))
                     (catch :default e e))]
          (is (= "dude" x)))
        (catch :default _ (is false))
        (finally (done))))))
We test both awaiting in throw, but also throwing in await

Harold 2026-01-24T14:31:43.555329Z

looks good to me 🙂