Skip to content

Commit 90ebc40

Browse files
committed
Improved output support for schema failures
* Stack pruning/elision * Trace tracking * Able to select stderr * Better config reporting on startup * Compact reporting option * Added validator memoization for malli
1 parent 009c961 commit 90ebc40

File tree

12 files changed

+500
-131
lines changed

12 files changed

+500
-131
lines changed

README.adoc

+25-5
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ You can control if spec failures are advisory or fatal by editing `guardrails.ed
9797

9898
Make sure to set your editor or IDE to resolve Guardrails' `>defn` and `>fdef` as Clojure's `defn`, and `>defn-` as `defn-` respectively – this way you get proper highlighting, formatting, error handling, structural navigation, symbol resolution, and refactoring support. A linting configuration for clj-kondo is included and should work out of the box.
9999

100+
=== Output Options
101+
102+
The configuration can be changed to help the signal to noise ratio on failures. If you have heavily instrumented your code with Guardrails, then turning on these two config options will likely give you a clearer picture on failures:
103+
104+
* `:guardrails/compact? true` - Remove blank/excess lines from the failure output.
105+
* `:guardrails/stack-trace :none` - Change what is shown for the stack trace. :none elides it, :prune causes a more pruned stack trace on a single line, and :full is the default of showing the whole thing.
106+
* `:guardrails/trace? true` - Shows the GR function call stack on failures (with argument values)
107+
108+
Try the above settings as shown. You can always see the full stack by calling `last-failure` (which is printed with any failures for convenience). The result is way less noisy, and often sufficient to find the problem. When it's not, the full stack trace is just a copy/paste away.
100109

101110
== Clojurescript Considerations
102111

@@ -355,10 +364,6 @@ The default config goes in the root of the project as `guardrails.edn`:
355364
:expound {:show-valid-values? true
356365
:print-specs? true}
357366
358-
;; Nilable map of Malli pretty-printer options
359-
:malli {:malli.dev.pretty/printer nil
360-
:malli.dev.printer/actor nil}
361-
362367
;; Check specs in parallel (CLJ only)
363368
:async? true
364369
@@ -371,11 +376,26 @@ The default config goes in the root of the project as `guardrails.edn`:
371376
;; call will be checked.
372377
:guardrails/mcps 100
373378
379+
;; Low-level stack trace output
380+
;; default :full
381+
:guardrails/stack-trace :prune ; or :full or :none
382+
383+
;; nREPL hates using stderr, but in other REPLs seeing your problems in red is nice.
384+
;; default false
385+
:guardrails/use-stderr? true
386+
387+
;; Optional (default false). Compress the explanation of the problem.
388+
:guardrails/compact? true
389+
390+
;; Keep track of the active GR-instrumented calls as a stack, and show that on errors.
391+
;; default false
392+
:guardrails/trace? true
393+
374394
;; should a spec failure on args or ret throw an exception?
375395
;; (always logs an informative message)
376396
:throw? false
377397
378-
;; should a spec failure be forwarded through tap> ?
398+
;; should a failure be forwarded through tap> ?
379399
:tap>? false}
380400
-----
381401

deps.edn

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"src/clj-kondo"],
33

44
:deps {expound/expound {:mvn/version "0.9.0"}
5-
com.taoensso/encore {:mvn/version "2.123.2"}
65
org.clojure/core.async {:mvn/version "1.6.673"}}
76

87
:aliases {:test {:extra-paths ["src/test" "src/test-clj-kondo"]

guardrails-test.edn

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
{:defn-macro nil
2-
:throw? true
3-
:expound {:show-valid-values? true
4-
:print-specs? true}}
1+
{:defn-macro nil
2+
:throw? true
3+
:guardrails/compact? true
4+
:guardrails/trace? true
5+
:guardrails/stack-trace :prune
6+
:expound {:show-valid-values? true
7+
:print-specs? true}}

guardrails.edn

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
{:defn-macro nil
2-
:throw? false
3-
:expound {:show-valid-values? true
4-
:print-specs? true}}
1+
{:defn-macro nil
2+
:throw? true
3+
:guardrails/compact? true
4+
:guardrails/trace? true
5+
:guardrails/stack-trace :none
6+
:expound {:show-valid-values? true
7+
:print-specs? true}}

pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@
7878
<artifactId>expound</artifactId>
7979
<version>0.9.0</version>
8080
</dependency>
81-
<dependency>
82-
<groupId>com.taoensso</groupId>
83-
<artifactId>encore</artifactId>
84-
<version>2.123.2</version>
85-
</dependency>
8681
<dependency>
8782
<groupId>org.clojure</groupId>
8883
<artifactId>core.async</artifactId>

src/main/com/fulcrologic/guardrails/config.cljc

+1-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@
161161
(when (and async? throw?)
162162
(utils/report-problem "INCOMPATIBLE MODES: :throw? and :async? cannot both be true. Disabling async."))
163163
(utils/report-info (str "Mode: " (mode result) (when (= :runtime (mode result))
164-
(str " Async? " (boolean (:async? result))
165-
" Throw? " (boolean (:throw? result))))))
164+
(str " config: " result))))
166165
(utils/report-info (str "Guardrails was enabled because "
167166
(if cljs-compiler-config
168167
"the CLJS Compiler config enabled it"

0 commit comments

Comments
 (0)