Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail fast #441

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/kaocha
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env bash
mkdir -p classes
clojure -M:aot
clojure -M:test -m kaocha.runner "$@"
4 changes: 3 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:paths ["src" "resources"]
{:paths ["src" "resources" "classes"]
:aliases {:test {:extra-paths ["test"]
:extra-deps {com.gfredericks/test.chuck {:mvn/version "0.2.11"}
lambdaisland/kaocha {:mvn/version "1.0.861"}
Expand All @@ -24,6 +24,8 @@
{:git/url "https://git.sr.ht/~severeoverfl0w/slow-namespace-clj"
:sha "f68d66d99d95f4d2bfd61f001e28a8ad7c4d3a12"}}
:main-opts ["-m" "io.dominic.slow-namespace-clj.core"]}
:aot {:extra-paths ["classes"]
:main-opts ["-e" "(compile,'malli.impl.NoStackException)"]}
:jar {:extra-deps {pack/pack.alpha
{:git/url "https://github.com/juxt/pack.alpha.git"
:sha "b093f79420fef019faf62a75b888b5e10f4e8cc9"}}
Expand Down
2 changes: 1 addition & 1 deletion src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
(defn -fail!
([type] (-fail! type nil))
([type data] (-fail! type nil data))
([type message data] (throw (ex-info (str type " " (pr-str data) message) {:type type, :data data}))))
([type message data] (throw (miu/-ex-info (str type " " (pr-str data) message) {:type type, :data data}))))

(defn -safe-pred [f] #(try (boolean (f %)) (catch #?(:clj Exception, :cljs js/Error) _ false)))

Expand Down
9 changes: 9 additions & 0 deletions src/malli/impl/NoStackException.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(ns malli.impl.NoStackException)

(gen-class
:name malli.impl.NoStackException
:extends clojure.lang.ExceptionInfo)

(defn -fillInStackTrace
([_])
([_ _]))
33 changes: 33 additions & 0 deletions src/malli/impl/util.cljc
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
(ns malli.impl.util
#?(:clj (:import (java.util.concurrent TimeoutException TimeUnit FutureTask)
(malli.impl NoStackException)
(clojure.lang MapEntry))))

#?(:clj
(defn no-stack-ex-info
"Allocate an exception without a stack trace."
[msg map]
(NoStackException. msg map)))

#?(:clj
(defn raw-ex-info
"Like [[clojure.core/ex-info]] but does not elide top frames."
[msg map]
(clojure.lang.ExceptionInfo. msg map)))

#?(:clj (def +ex-info+ (atom ex-info)))

#?(:clj
(defn set-ex-info!
"Set ex-info function to one of three modes:
- default: [[clojure.core/ex-info]]
- raw: [[raw-ex-info]], does not elide top frames
- no-stacktrace: [[no-stack-ex-info]], fastest, does not create stack trace."
[mode]
(reset!
+ex-info+
(case mode
:default ex-info
:raw raw-ex-info
:no-stacktrace no-stack-ex-info))))

(defn -ex-info
[msg map]
(#?(:clj @+ex-info+ :cljs ex-info) msg map))

(def ^:const +max-size+ #?(:clj Long/MAX_VALUE, :cljs (.-MAX_VALUE js/Number)))

(defn -tagged [k v] #?(:clj (MapEntry. k v), :cljs (MapEntry. k v nil)))
Expand Down