Skip to content

Commit

Permalink
Prefix RethinkDB server exceptions with RethinkDB server:
Browse files Browse the repository at this point in the history
It is sometimes difficult for people to distinguish between an exception
thrown in the client library, and an exception from the server which is
sent back and thrown by the client library. This change prefixes
serverside exceptions to make this distinction clearer.

Fixes #95, fixes #94
  • Loading branch information
danielcompton committed Nov 19, 2015
1 parent f9e46d4 commit 694266a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. This change
- Disable Nagle's algorithm (set TCP NO_DELAY to true). This provides a speedup of around 30-40x for small queries on Linux. [#114](https://github.com/apa512/clj-rethinkdb/pull/114)
- Added a new arity to `changes` that allows you to pass optargs. [#112](https://github.com/apa512/clj-rethinkdb/issues/112)
- Renamed changes arg from `table` to `xs`. [#76](https://github.com/apa512/clj-rethinkdb/issues/76)
- Prefix RethinkDB server exceptions with `RethinkDB server:`. [#100](https://github.com/apa512/clj-rethinkdb/pull/100)


## [0.11.0] - 2015-10-19
Expand Down
2 changes: 1 addition & 1 deletion src/rethinkdb/net.clj
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
(do
(swap! (:conn conn) update-in [:waiting] #(conj % token))
(Cursor. conn token resp)))
(let [ex (ex-info (str (first resp)) json-resp)]
(let [ex (ex-info (str "RethinkDB server: " (first resp)) json-resp)]
(log/error ex)
(throw ex)))))

Expand Down
17 changes: 14 additions & 3 deletions test/rethinkdb/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[clojure.test :refer :all]
[rethinkdb.query :as r]
[rethinkdb.core :as core]
[rethinkdb.net :as net]))
[rethinkdb.net :as net])
(:import (clojure.lang ExceptionInfo)))

(def test-db "cljrethinkdb_test")
(def test-table :pokedex)
Expand Down Expand Up @@ -359,12 +360,22 @@
(r/get-field :name))
conn))))))

(deftest throwing-server-exceptions
(with-open [conn (r/connect :db test-db)]
(is (thrown? ExceptionInfo (r/run (r/table :nope) conn)))
(try (r/run (r/table :nope) conn)
(catch ExceptionInfo ex
(let [{:keys [r]} (ex-data ex)
msg (.getMessage ex)]
(is (= r ["Table `cljrethinkdb_test.nope` does not exist."]))
(is (= "RethinkDB server: Table `cljrethinkdb_test.nope` does not exist." msg)))))))

(deftest query-conn
(is (do (r/connect)
true))
(is (thrown? clojure.lang.ExceptionInfo (r/connect :port 1)))
(is (thrown? ExceptionInfo (r/connect :port 1)))
(with-redefs-fn {#'core/send-version (fn [out] (net/send-int out 168696 4))}
#(is (thrown? clojure.lang.ExceptionInfo (r/connect)))))
#(is (thrown? ExceptionInfo (r/connect)))))

(use-fixtures :each setup-each)
(use-fixtures :once setup-once)

0 comments on commit 694266a

Please sign in to comment.