Skip to content

Commit 5ba0c43

Browse files
committed
Don't swallow exceptions from parsing json
When Etaoin failed parse a json webdriver response, it would swallow the exception. This lead to confusing "empty page" exceptions. We now let the true json parse exception to flow through. Closes #696
1 parent 1cdd75e commit 5ba0c43

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

CHANGELOG.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ A release with an intentional breaking changes is marked with:
2222
* Changes
2323
** Bumped deps.
2424
({lread})
25+
** {issue}696[#696]: Stop hiding json parse exceptions
26+
({lread})
2527
** {issue}676[#676]: Fix new driver creation so that it sidesteps some underlying Firefox race conditions and improves CI test stability. ({person}dgr[@dgr])
2628
** {issue}679[#679]: Add `new-window` function that exposes WebDriver's New Window endpoint. ({person}dgr[@dgr])
2729
** {issue}682[#682]: Fixed a bug in `fill-human-multi` to correctly call `fill-human` rather than `fill`. ({person}dgr[@dgr])

src/etaoin/impl/client.clj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@
5050

5151
(defn- parse-json [body]
5252
(let [body* (str/replace body #"Invalid Command Method -" "")]
53-
(try
54-
(json/parse-string body* true)
55-
(catch Throwable _ body))))
53+
(json/parse-string body* true)))
5654

5755
(defn- error-response [body]
5856
(if (string? body)

test/etaoin/api_test.clj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[babashka.fs :as fs]
44
[babashka.process :as p]
55
[cheshire.core :as json]
6+
[cheshire.factory :as cheshire-factory]
67
[clojure.edn :as edn]
78
[clojure.java.io :as io]
89
[clojure.java.shell :as shell]
@@ -1333,6 +1334,16 @@
13331334
(is (do (e/set-page-load-timeout *driver* 100/3)
13341335
true))))
13351336

1337+
(deftest test-json-parse-error
1338+
;; output pdf should never be created, but just in case...
1339+
(let [out-pdf (-> (fs/create-temp-file {:prefix "print-page" :suffix "pdf"})
1340+
fs/delete-on-exit)]
1341+
(is (thrown-with-msg?
1342+
Exception #"(?i)string.*exceeds.*512"
1343+
(binding [cheshire-factory/*json-factory* (cheshire-factory/make-json-factory
1344+
{:max-input-string-length 512})]
1345+
(e/print-page *driver* out-pdf))))))
1346+
13361347
(comment
13371348
;; start test server
13381349
(def test-server (p/process {:out :inherit :err :inherit} "bb test-server --port" 9993))

0 commit comments

Comments
 (0)