Welcome! Please see the About page for a little more info on how this works.

+2 votes
in Errors by
retagged by

Put anywhere in bad_line_number.clj, run with clj -J-Dclojure.main.report=stderr -Sdeps '{:paths ["."]}' -M -m bad-line-number from the same dir.

(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]))

Running that code results in

{: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

As you can see, it refers to line 10, which has (let [[a fmt] (returns-a-tuple), so naturally the first line of thinking is "returns-a-tuple somehow returns a map, and that's what I need to investigate".
Just spent a few hours chasing that goose when it's actually should-also-return-a-tuple-but-doesnt that's to blame.

1 Answer

0 votes
by
selected by
...