在bad_line_number.clj
的任何位置放入,从同一目录运行clj -J-Dclojure.main.report=stderr -Sdeps '{:paths ["."]}' -M -m bad-line-number
。
(ns bad-line-number)
(defn returns-a-tuple []
[{1 2} :wrapped])
(defn should-also-return-a-tuple-but-doesnt [data]
{data :unwrapped})
(defn -main []
(let [[a fmt] (returns-a-tuple)
data
(try
(should-also-return-a-tuple-but-doesnt a)
(catch Throwable _
(println "Unable to create a map")
[3 4]))
[x y]
(case fmt
:wrapped data
:unwrapped [data nil])]
[x y]))
运行此代码的结果是
{:clojure.main/message
"Execution error (UnsupportedOperationException) at bad-line-number/-main (bad_line_number.clj:10).\nnth not supported on this type: PersistentArrayMap\n",
:clojure.main/triage
{:clojure.error/class java.lang.UnsupportedOperationException,
:clojure.error/line 10,
:clojure.error/cause
"nth not supported on this type: PersistentArrayMap",
:clojure.error/symbol bad-line-number/-main,
:clojure.error/source "bad_line_number.clj",
:clojure.error/phase :execution},
:clojure.main/trace
{:via
[{:type java.lang.UnsupportedOperationException,
:message "nth not supported on this type: PersistentArrayMap",
:at [clojure.lang.RT nthFrom "RT.java" 992]}],
:trace
[[clojure.lang.RT nthFrom "RT.java" 992]
[clojure.lang.RT nth "RT.java" 940]
[bad_line_number$_main invokeStatic "bad_line_number.clj" 10]
[bad_line_number$_main invoke "bad_line_number.clj" 9]
[clojure.lang.AFn applyToHelper "AFn.java" 152]
[clojure.lang.AFn applyTo "AFn.java" 144]
[clojure.lang.Var applyTo "Var.java" 705]
[clojure.core$apply invokeStatic "core.clj" 667]
[clojure.main$main_opt invokeStatic "main.clj" 514]
[clojure.main$main_opt invoke "main.clj" 510]
[clojure.main$main invokeStatic "main.clj" 664]
[clojure.main$main doInvoke "main.clj" 616]
[clojure.lang.RestFn applyTo "RestFn.java" 137]
[clojure.lang.Var applyTo "Var.java" 705]
[clojure.main main "main.java" 40]],
:cause "nth not supported on this type: PersistentArrayMap"}}
Execution error (UnsupportedOperationException) at bad-line-number/-main (bad_line_number.clj:10).
nth not supported on this type: PersistentArrayMap
如您所见,它引用了第10行,该行有(let [[a fmt] (returns-a-tuple)
,所以自然而然的第一个想法是"returns-a-tuple
以某种方式返回一个映射,这就是我需要调查的内容"。
刚刚花了几小时追逐这只鹅,而实际上要负责任的是should-also-return-a-tuple-but-doesnt
。