Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace etaoin.impl.util/error with Slingshot throw+ #667

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ A release with an intentional breaking changes is marked with:
** {issue}657[#657]: Make `set-<xyz>-timeout` functions resilient to reasonable non-integer timeouts (e.g., rationals, doubles, etc.). ({person}dgr[@dgr])
** {issue}661[#661]: Fix `:fn/enabled`. ({person}dgr[@dgr])
** {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])
** {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])
* Docs
** {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])
* Quality
Expand Down
16 changes: 11 additions & 5 deletions src/etaoin/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3059,7 +3059,8 @@
:path [:session (:session driver) :screenshot]})
b64str (-> resp :value not-empty)]
(when (not b64str)
(util/error "Empty screenshot"))
(throw+ {:type :etaoin/failed
:message "Empty screenshot"}))
(create-dirs-for-file file)
(b64-to-file b64str file)))

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

Expand Down Expand Up @@ -3129,8 +3132,10 @@

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

(defmethods print-page
[:chrome :edge :firefox]
Expand All @@ -3141,7 +3146,8 @@
:data opts})
b64str (-> resp :value not-empty)]
(when (not b64str)
(util/error "Empty page"))
(throw+ {:type :etaoin/failed
:message "Empty page"}))
(create-dirs-for-file file)
(b64-to-file b64str file)))

Expand Down
6 changes: 0 additions & 6 deletions src/etaoin/impl/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@
[& args]
(mapv class args))

(defn error
([msg]
(throw (Exception. ^String msg)))
([tpl & args]
(error (apply format tpl args))))

(defn get-free-port []
(let [socket (ServerSocket. 0)]
(.close socket)
Expand Down
8 changes: 5 additions & 3 deletions src/etaoin/query.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Why do folks need to use this directly?
Maybe they are extending defmulti with more conversions?"
(:require
[etaoin.impl.util :as util]
[etaoin.impl.xpath :as xpath]))
[etaoin.impl.xpath :as xpath]
[slingshot.slingshot :refer [throw+]]))

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

Expand Down Expand Up @@ -51,7 +51,9 @@

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

(defn expand
"Return expanded query `q` for `driver`."
Expand Down
Loading