Skip to content

Commit de15ba8

Browse files
author
dnolen
committed
CLJS-1034: Support REPL-defined functions in stacktrace infrastructure
Make `cljs.repl/mapped-stacktrace` nil safe for all the stack element components. If handed :file that starts with "<" or nil :file prepend "NO_SOURCE_FILE" a la Clojure. Smarter printing for nil values of a stack element.
1 parent cf5fccc commit de15ba8

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

src/clj/cljs/repl.clj

+25-14
Original file line numberDiff line numberDiff line change
@@ -260,28 +260,39 @@
260260
(vec
261261
(for [{:keys [function file line column] :as frame} stacktrace]
262262
;; need to convert file, a relative URL style path, to host-specific file
263-
(let [rfile (io/file (URL. (.toURL (io/file (util/output-directory opts))) file))
263+
(let [no-source-file? (if-not file
264+
true
265+
(.startsWith file "<"))
266+
rfile (when-not no-source-file?
267+
(io/file (URL. (.toURL (io/file (util/output-directory opts))) file)))
264268
[sm {:keys [ns source-file] :as ns-info}]
265-
((juxt read-source-map' ns-info') rfile)
269+
(when-not no-source-file?
270+
((juxt read-source-map' ns-info') rfile))
266271
[line' column'] (if ns-info
267272
(mapped-line-and-column sm line column)
268273
[line column])
269274
name' (if (and ns-info function)
270275
(symbol (name ns) (cljrepl/demunge function))
271276
function)
272-
file' (string/replace
273-
(.getCanonicalFile
274-
(if ns-info
275-
source-file
276-
(io/file rfile)))
277-
(str (System/getProperty "user.dir") File/separator) "")
277+
file' (if no-source-file?
278+
file
279+
(string/replace
280+
(.getCanonicalFile
281+
(if ns-info
282+
source-file
283+
(io/file rfile)))
284+
(str (System/getProperty "user.dir") File/separator) ""))
278285
url (or (and ns-info (io/resource (util/ns->relpath ns)))
279-
(io/resource file))]
286+
(and file (io/resource file)))]
280287
(merge
281288
{:function name'
282-
:file (io/file file')
283-
:line line'
284-
:column column'}
289+
:file (if no-source-file?
290+
(str "NO_SOURCE_FILE"
291+
(when file
292+
(str " " file)))
293+
(io/file file'))
294+
:line line'
295+
:column column'}
285296
(when url
286297
{:url url}))))))))
287298

@@ -293,8 +304,8 @@
293304
(doseq [{:keys [function file line column]}
294305
(mapped-stacktrace stacktrace opts)]
295306
((:print opts) "\t"
296-
(str (and function (str function " "))
297-
"(" file ":" line ":" column ")")))))
307+
(str (when function (str function " "))
308+
"(" file (when line (str ":" line)) (when column (str ":" column)) ")")))))
298309

299310
(comment
300311
(cljsc/build "samples/hello/src"

0 commit comments

Comments
 (0)