|
1654 | 1654 | (is (str/includes? (str st) "1:31")))) |
1655 | 1655 |
|
1656 | 1656 | (deftest sci-error-multiple-catches-test |
1657 | | - #?(:clj |
1658 | | - (testing "^:sci/error works with multiple catch clauses - specific catch first" |
1659 | | - (let [result (sci/eval-string |
1660 | | - "(defn foo [] (/ 1 0)) |
| 1657 | + (testing "^:sci/error works with multiple catch clauses - specific catch first" |
| 1658 | + (let [result (sci/eval-string |
| 1659 | + (-> "(defn foo [] (/ 1 0)) |
1661 | 1660 | (defn bar [] |
1662 | 1661 | (try (foo) |
1663 | 1662 | (catch ArithmeticException e |
1664 | 1663 | {:caught :arithmetic :msg (ex-message e)}) |
1665 | 1664 | (catch ^:sci/error Exception e |
1666 | 1665 | {:caught :exception}))) |
1667 | 1666 | (bar)" |
1668 | | - {:classes {'ArithmeticException ArithmeticException}})] |
1669 | | - (is (= :arithmetic (:caught result))) |
1670 | | - (is (str/includes? (:msg result) "Divide by zero"))))) |
| 1667 | + #?(:cljs (str/replace "ArithmeticException" "js/RangeError")) |
| 1668 | + #?(:cljs (str/replace "Exception" "js/Error")) |
| 1669 | + #?(:cljs (str/replace "(/ 1 0)" "(js/Array. -1)"))) |
| 1670 | + {:classes #?(:clj {'ArithmeticException ArithmeticException} |
| 1671 | + :cljs {:allow :all 'js js/global})})] |
| 1672 | + (is (= :arithmetic (:caught result))) |
| 1673 | + (is (str/includes? (:msg result) #?(:clj "Divide by zero" |
| 1674 | + :cljs "Invalid array length"))))) |
1671 | 1675 | (testing "^:sci/error Exception catch still gets location info with multiple catches" |
1672 | 1676 | (let [result (sci/eval-string |
1673 | 1677 | (-> "(require '[sci.core :as sci]) |
1674 | 1678 | (defn foo [] (assoc :foo :bar)) |
1675 | 1679 | (defn bar [] |
1676 | 1680 | (try (foo) |
1677 | | - (catch java.io.FileNotFoundException e |
| 1681 | + (catch ArithmeticException e |
1678 | 1682 | {:caught :not-found}) |
1679 | 1683 | (catch ^:sci/error Exception e |
1680 | 1684 | {:caught :exception :st (sci/format-stacktrace (sci/stacktrace e))}))) |
1681 | 1685 | (bar)" |
1682 | | - #?(:cljs (str/replace "java.io.FileNotFoundException" "js/RangeError")) |
| 1686 | + #?(:cljs (str/replace "ArithmeticException" "js/RangeError")) |
1683 | 1687 | #?(:cljs (str/replace "Exception" "js/Error"))) |
1684 | | - {:classes #?(:clj {'java.io.FileNotFoundException java.io.FileNotFoundException} |
| 1688 | + {:classes #?(:clj {'ArithmeticException ArithmeticException} |
1685 | 1689 | :cljs {:allow :all 'js js/global}) |
1686 | 1690 | :namespaces {'sci.core {'stacktrace sci/stacktrace |
1687 | 1691 | 'format-stacktrace sci/format-stacktrace}}})] |
|
0 commit comments