Fix #1771: *e should contain exception thrown by user (#1784)

This commit is contained in:
Michiel Borkent 2024-12-20 17:20:45 +01:00 committed by GitHub
parent 142e9eae06
commit 024f1d5515
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 17 deletions

View file

@ -9,10 +9,11 @@ A preview of the next release can be installed from
## Unreleased
- [#1777] Add java.nio.file.attribute.UserDefinedFileAttributeView
- [#1776] Add java.nio.file.attribute.PosixFileAttributes
- [#1761] Support calling `clojure.lang.RT/iter`
- [#1760] For compatibility with [Fireworks v0.10.3](https://github.com/paintparty/fireworks), added the following to `:instance-checks` entry in `babashka.impl.classes/classes`([@paintparty](https://github.com/paintparty))
- [#1771](https://github.com/babashka/babashka/issues/1771): `*e*` in REPL should contain exception thrown by user, not a wrapped one
- [#1777](https://github.com/babashka/babashka/issues/1777) Add java.nio.file.attribute.UserDefinedFileAttributeView
- [#1776](https://github.com/babashka/babashka/issues/1776) Add java.nio.file.attribute.PosixFileAttributes
- [#1761](https://github.com/babashka/babashka/issues/1761) Support calling `clojure.lang.RT/iter`
- [#1760](https://github.com/babashka/babashka/issues/1760) For compatibility with [Fireworks v0.10.3](https://github.com/paintparty/fireworks), added the following to `:instance-checks` entry in `babashka.impl.classes/classes`([@paintparty](https://github.com/paintparty))
- `clojure.lang.PersistentArrayMap$TransientArrayMap`
- `clojure.lang.PersistentHashMap$TransientHashMap`
- `clojure.lang.PersistentVector$TransientVector`

View file

@ -118,8 +118,9 @@ by default when a new command-line REPL is started."} repl-requires
:file "<repl>"
:type :sci/error) e)))))))
(catch Throwable e
(caught e)
(set! *e e))))]
(let [e' (ex-cause e)]
(caught e)
(set! *e e')))))]
(with-bindings
(try
(init)

View file

@ -43,7 +43,7 @@
"Inspired by skip-if-eol from clojure.main."
[s]
(let [c (r/read-char s)]
(when-not (= c \newline)
(when-not (= \newline c )
(r/unread s c))))
(defn repl-read [sci-ctx in-stream _request-prompt request-exit]

View file

@ -26,15 +26,15 @@
(sci/with-in-str (str expr "\n:repl/quit")
(repl!)))) expected)))
(defn assert-repl-error [expr expected]
(is (str/includes?
(tu/normalize
(let [sw (java.io.StringWriter.)]
(sci/binding [sci/out (java.io.StringWriter.)
sci/err sw]
(sci/with-in-str (str expr "\n:repl/quit")
(repl!)))
(str sw))) expected)))
(defmacro assert-repl-error [expr expected]
`(is (str/includes?
(tu/normalize
(let [sw# (java.io.StringWriter.)]
(sci/binding [sci/out (java.io.StringWriter.)
sci/err sw#]
(sci/with-in-str (str ~expr "\n:repl/quit")
(repl!)))
(str sw#))) ~expected)))
(deftest repl-test
(assert-repl "1" "1")
@ -52,7 +52,9 @@
(assert-repl-error "(+ 1 nil)" "NullPointerException")
(assert-repl-error "(/ 1 0) (pst 1)" "Divide by zero\n\tclojure.lang.Numbers")
(assert-repl-error "(partition (range 5) 3)"
"Don't know how to create ISeq from: java.lang.Long"))
"Don't know how to create ISeq from: java.lang.Long")
(assert-repl "(throw (ex-info \"foo\" {:a (+ 1 2 3)})) (ex-data *e)"
"{:a 6}"))
;;;; Scratch