Skip to content

Commit

Permalink
added support for tracing exceptions in trace/trace-var
Browse files Browse the repository at this point in the history
  • Loading branch information
jlangch committed Mar 30, 2024
1 parent babea24 commit fa7cf3c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file.
- function `io/file-normalize-utf`
- thread type support to the function `thread` to allow spawning daemon or user
threads
- support for tracing exceptions in `trace/trace-var`



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public DocSection section() {
final DocSection trace = new DocSection("Tracing", id());
all.addSection(trace);
trace.addItem(diBuilder.getDocItem("trace/trace"));
trace.addItem(diBuilder.getDocItem("trace/trace-var"));
trace.addItem(diBuilder.getDocItem("trace/trace-var", true, true));
trace.addItem(diBuilder.getDocItem("trace/untrace-var"));

final DocSection test = new DocSection("Test", id());
Expand Down
25 changes: 21 additions & 4 deletions src/main/resources/com/github/jlangch/venice/trace.venice
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@
(let [id (gensym "t")]
(tracer id (str (trace-indent) (pr-str (cons name args))))
(binding [*trace-depth* (inc *trace-depth*)]
(let [result (apply f args)]
(tracer id (str (trace-indent) "=> " (pr-str result)))
result))))
(try
(let [result (apply f args)]
(tracer id (str (trace-indent) "=> " (pr-str result)))
result)
(catch :Exception e
(tracer id (str (trace-indent) "=> " (pr-str e)))
(throw e))))))


(defn
Expand Down Expand Up @@ -150,7 +154,7 @@
(t/trace-var +)

(+ 1 2))
"""
""",
"""
(do
(load-module :trace ['trace :as 't])
Expand All @@ -163,6 +167,19 @@
(t/trace-var foo)
(t/trace-var bar)

(bar 5))
""",
"""
(do
(load-module :trace ['trace :as 't])

(defn foo [x] (/ x 0)) ;; division by zero!
(defn bar [x] (foo x))

(t/trace-var /)
(t/trace-var foo)
(t/trace-var bar)

(bar 5))
""" )
:see-also '(
Expand Down

0 comments on commit fa7cf3c

Please sign in to comment.