Skip to content

Commit 1ea781e

Browse files
authored
Replace etaoin.impl.util/error with Slingshot throw+ (#667)
1 parent c37f4df commit 1ea781e

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

CHANGELOG.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ A release with an intentional breaking changes is marked with:
3232
** {issue}657[#657]: Make `set-<xyz>-timeout` functions resilient to reasonable non-integer timeouts (e.g., rationals, doubles, etc.). ({person}dgr[@dgr])
3333
** {issue}661[#661]: Fix `:fn/enabled`. ({person}dgr[@dgr])
3434
** {issue}663[#663]: `query` throws a more accurate exception with a more accurate error message when provided with an empty query vector. ({person}dgr[@dgr])
35+
** {issue}666[#666]: Previously, in some error conditions, Etaoin would throw a very generic `clojure.lang.Exception` object. Some of those cases have been replaced by throwing a map with Slingshot, providing more information about the problem. ({person}dgr[@dgr])
3536
* Docs
3637
** {issue}656[#656]: Correctly describe behavior when query's parameter is a string. The User Guide and `query` doc strings say that a string passed to `query` is interpreted as an XPath expression. In fact, `query` interprets this as either XPath or CSS depending on the setting of the driver's `:locator` parameter, which can be changed. ({person}dgr[@dgr])
3738
* Quality

src/etaoin/api.clj

+11-5
Original file line numberDiff line numberDiff line change
@@ -3059,7 +3059,8 @@
30593059
:path [:session (:session driver) :screenshot]})
30603060
b64str (-> resp :value not-empty)]
30613061
(when (not b64str)
3062-
(util/error "Empty screenshot"))
3062+
(throw+ {:type :etaoin/failed
3063+
:message "Empty screenshot"}))
30633064
(create-dirs-for-file file)
30643065
(b64-to-file b64str file)))
30653066

@@ -3078,7 +3079,9 @@
30783079
:path [:session (:session driver) :element el :screenshot]})
30793080
b64str (-> resp :value not-empty)]
30803081
(when (not b64str)
3081-
(util/error "Empty screenshot, query: %s" q))
3082+
(throw+ {:type :etaoin/failed
3083+
:message "Empty screenshot"
3084+
:q q}))
30823085
(create-dirs-for-file file)
30833086
(b64-to-file b64str file)))
30843087

@@ -3129,8 +3132,10 @@
31293132

31303133
(defmethod print-page
31313134
:default ;; last checked safari 2024-08-08
3132-
[_driver _file & [_opts]]
3133-
(util/error "This driver doesn't support printing pages to PDF."))
3135+
[driver _file & [_opts]]
3136+
(throw+ {:type :etaoin/unsupported
3137+
:message "This driver doesn't support printing pages to PDF."
3138+
:driver driver}))
31343139

31353140
(defmethods print-page
31363141
[:chrome :edge :firefox]
@@ -3141,7 +3146,8 @@
31413146
:data opts})
31423147
b64str (-> resp :value not-empty)]
31433148
(when (not b64str)
3144-
(util/error "Empty page"))
3149+
(throw+ {:type :etaoin/failed
3150+
:message "Empty page"}))
31453151
(create-dirs-for-file file)
31463152
(b64-to-file b64str file)))
31473153

src/etaoin/impl/util.clj

-6
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@
3535
[& args]
3636
(mapv class args))
3737

38-
(defn error
39-
([msg]
40-
(throw (Exception. ^String msg)))
41-
([tpl & args]
42-
(error (apply format tpl args))))
43-
4438
(defn get-free-port []
4539
(let [socket (ServerSocket. 0)]
4640
(.close socket)

src/etaoin/query.clj

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
Why do folks need to use this directly?
66
Maybe they are extending defmulti with more conversions?"
77
(:require
8-
[etaoin.impl.util :as util]
9-
[etaoin.impl.xpath :as xpath]))
8+
[etaoin.impl.xpath :as xpath]
9+
[slingshot.slingshot :refer [throw+]]))
1010

1111
(set! *warn-on-reflection* true)
1212

@@ -51,7 +51,9 @@
5151

5252
(defmethod to-query :default
5353
[_driver q]
54-
(util/error "Wrong query: %s" q))
54+
(throw+ {:type :etaoin/argument
55+
:message "Unsupported query argument type"
56+
:q q}))
5557

5658
(defn expand
5759
"Return expanded query `q` for `driver`."

0 commit comments

Comments
 (0)