Skip to content

Commit c8877f3

Browse files
authored
Merge pull request #36 from GAumala/promesa-three-state-detection
Fail fast on a too-old funcool/promesa instead of a cryptic load error
2 parents 9183da7 + 1758b9f commit c8877f3

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/main/com/fulcrologic/statecharts/promise.cljc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,28 @@
4242
true
4343
(catch Throwable _ false))))
4444

45+
;; Fail fast on a present-but-too-old promesa. `promesa.core/await!` was added
46+
;; in 10.0.570; older versions (e.g. 8.0.450) load fine but lack it, so the
47+
;; `(intern ... (deref (resolve 'promesa.core/await!)))` below blows up while
48+
;; this namespace is loading. The resulting failure is cryptic and far from the
49+
;; root cause (e.g. under shadow-cljs it surfaces as a macro-loading error like
50+
;; `No namespace: com.fulcrologic.statecharts.promise found`). Silently falling
51+
;; back to native mode would also be unsafe: native `promise?` is
52+
;; `(instance? IPending v)`, but a real promesa JVM promise is a CompletionStage
53+
;; (NOT IPending), so async expressions returning promesa promises would be
54+
;; mis-handled by the engine. So this is a hard error with an actionable message.
55+
#?(:clj
56+
(when (and promesa-available?
57+
(nil? (resolve 'promesa.core/await!)))
58+
(throw (ex-info
59+
(str "An outdated funcool/promesa is on the classpath: "
60+
"com.fulcrologic.statecharts.promise requires promesa.core/await!, "
61+
"which was added in promesa 10.0.570. Upgrade funcool/promesa to "
62+
">= 10.0.570 (or remove it from the classpath entirely to use the "
63+
"native, promesa-free fallback).")
64+
{:missing-promesa-sym 'promesa.core/await!
65+
:min-promesa-version "10.0.570"}))))
66+
4567
#?(:clj
4668
(def ^:no-doc mode
4769
"One of `:promesa` or `:native`. CLJ runtime only. Useful for tests

0 commit comments

Comments
 (0)