1
0
mirror of https://github.com/janet-lang/janet synced 2024-10-01 16:30:40 +00:00

Remove redundant stuff from stacktrace.

Rather than try and make ascii art, focus on whether information
is present in the stack trace that peoplpe actually need, and be terse.

Tools can better handler simpler and more stable interfaces.
This commit is contained in:
Calvin Rose 2024-05-26 11:39:08 -05:00
parent 74560ff805
commit 16ac681ed9

View File

@ -2405,33 +2405,6 @@
(defdyn *err-color*
"Whether or not to turn on error coloring in stacktraces and other error messages.")
(defdyn *err-line-col*
"Whether or not to print the line of source code that caused an error.")
(defn- print-line-col
``Print the source code at a line, column in a source file. If unable to open
the file, prints nothing.``
[where line col]
(if-not line (break))
(unless (string? where) (break))
(unless (dyn *err-line-col*) (break))
(def ec (dyn *err-color*))
(when-with [f (file/open where :r)]
(def source-code (file/read f :all))
(var index 0)
(repeat (dec line)
(if-not index (break))
(set index (string/find "\n" source-code index))
(if index (++ index)))
(when index
(def line-end (string/find "\n" source-code index))
(def s (if ec "\e[31m"))
(def e (if ec "\e[0m"))
(eprint s " " (string/slice source-code index line-end) e)
(when col
(+= index col)
(eprint s (string/repeat " " (inc col)) "^" e)))))
(defn bad-parse
"Default handler for a parse error."
[p where]
@ -2447,7 +2420,6 @@
": parse error: "
(:error p)
(if ec "\e[0m"))
(print-line-col where line col)
(eflush))
(defn warn-compile
@ -2463,7 +2435,6 @@
col
": compile warning (" level "): ")
(eprint msg (if ec "\e[0m"))
(print-line-col where line col)
(eflush))
(defn bad-compile
@ -2481,7 +2452,6 @@
(if macrof
(debug/stacktrace macrof msg "")
(eprint msg (if ec "\e[0m")))
(print-line-col where line col)
(eflush))
(defn curenv