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 ## Unreleased
- [#1777] Add java.nio.file.attribute.UserDefinedFileAttributeView - [#1771](https://github.com/babashka/babashka/issues/1771): `*e*` in REPL should contain exception thrown by user, not a wrapped one
- [#1776] Add java.nio.file.attribute.PosixFileAttributes - [#1777](https://github.com/babashka/babashka/issues/1777) Add java.nio.file.attribute.UserDefinedFileAttributeView
- [#1761] Support calling `clojure.lang.RT/iter` - [#1776](https://github.com/babashka/babashka/issues/1776) Add java.nio.file.attribute.PosixFileAttributes
- [#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)) - [#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.PersistentArrayMap$TransientArrayMap`
- `clojure.lang.PersistentHashMap$TransientHashMap` - `clojure.lang.PersistentHashMap$TransientHashMap`
- `clojure.lang.PersistentVector$TransientVector` - `clojure.lang.PersistentVector$TransientVector`

View file

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

View file

@ -43,7 +43,7 @@
"Inspired by skip-if-eol from clojure.main." "Inspired by skip-if-eol from clojure.main."
[s] [s]
(let [c (r/read-char s)] (let [c (r/read-char s)]
(when-not (= c \newline) (when-not (= \newline c )
(r/unread s c)))) (r/unread s c))))
(defn repl-read [sci-ctx in-stream _request-prompt request-exit] (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") (sci/with-in-str (str expr "\n:repl/quit")
(repl!)))) expected))) (repl!)))) expected)))
(defn assert-repl-error [expr expected] (defmacro assert-repl-error [expr expected]
(is (str/includes? `(is (str/includes?
(tu/normalize (tu/normalize
(let [sw (java.io.StringWriter.)] (let [sw# (java.io.StringWriter.)]
(sci/binding [sci/out (java.io.StringWriter.) (sci/binding [sci/out (java.io.StringWriter.)
sci/err sw] sci/err sw#]
(sci/with-in-str (str expr "\n:repl/quit") (sci/with-in-str (str ~expr "\n:repl/quit")
(repl!))) (repl!)))
(str sw))) expected))) (str sw#))) ~expected)))
(deftest repl-test (deftest repl-test
(assert-repl "1" "1") (assert-repl "1" "1")
@ -52,7 +52,9 @@
(assert-repl-error "(+ 1 nil)" "NullPointerException") (assert-repl-error "(+ 1 nil)" "NullPointerException")
(assert-repl-error "(/ 1 0) (pst 1)" "Divide by zero\n\tclojure.lang.Numbers") (assert-repl-error "(/ 1 0) (pst 1)" "Divide by zero\n\tclojure.lang.Numbers")
(assert-repl-error "(partition (range 5) 3)" (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 ;;;; Scratch