Public Vars

Back

ex-message (clj)

(source)

function

(ex-message ex)
Returns the message attached to ex if ex is a Throwable. Otherwise returns nil.

Examples

seancorfield/next-jdbc
(ns next.jdbc-test
  "Basic tests for the primary API of `next.jdbc`."
  (:require [clojure.core.reducers :as r]
            [clojure.string :as str]
            [clojure.test :refer [deftest is testing use-fixtures]]
            [next.jdbc :as jdbc]
            [next.jdbc.connection :as c]
            [next.jdbc.test-fixtures
             :refer [with-test-db db ds column
                     default-options stored-proc?
                     derby? hsqldb? jtds? mssql? mysql? postgres? sqlite?]]
            [next.jdbc.prepare :as prep]
            [next.jdbc.result-set :as rs]
            [next.jdbc.specs :as specs]
            [next.jdbc.types :as types])
  (:import (com.zaxxer.hikari HikariDataSource)
           (com.mchange.v2.c3p0 ComboPooledDataSource PooledDataSource)
           (java.sql ResultSet ResultSetMetaData)))

#_
(deftest duplicate-insert-test
  ;; this is primarily a look at exception types/information for #226
  (try
    (jdbc/execute! (ds) ["
    INSERT INTO fruit (id, name, appearance, cost, grade)
    VALUES (1234, '1234', '1234', 1234, 1234)
    "])
    (try
      (jdbc/execute! (ds) ["
      INSERT INTO fruit (id, name, appearance, cost, grade)
      VALUES (1234, '1234', '1234', 1234, 1234)
      "])
      (println (:dbtype (db)) "allowed duplicate insert")
      (catch java.sql.SQLException t
        (println (:dbtype (db)) "duplicate insert threw" (type t)
                 "error" (.getErrorCode t) "state" (.getSQLState t)
                 "\n\t" (ex-message t))))
    (catch java.sql.SQLException t
      (println (:dbtype (db)) "will not allow specific ID" (type t)
               "error" (.getErrorCode t) "state" (.getSQLState t)
               "\n\t" (ex-message t)))))

(deftest multi-rs
  (when (mssql?)
    (testing "script with multiple result sets"
      (let [multi-rs
            (jdbc/execute! (ds)
                           [(str "begin"
                                 " select * from fruit;"
                                 " select * from fruit where id < 4;"
                                 " end")]
                           {:multi-rs true})]
        (is (= 2 (count multi-rs)))
        (is (= 4 (count (first multi-rs))))
        (is (= 3 (count (second multi-rs)))))))
  (when (mysql?)
    (testing "script with multiple result sets"
      (let [multi-rs
            (jdbc/execute! (ds)
                           [(str "select * from fruit;"
                                 " select * from fruit where id < 4")]
                           {:multi-rs true})]
        (is (= 2 (count multi-rs)))
        (is (= 4 (count (first multi-rs))))
        (is (= 3 (count (second multi-rs)))))))
  (when (stored-proc?)
    (testing "stored proc; multiple result sets"
      (try
        (let [multi-rs
              (jdbc/execute! (ds)
                             [(if (mssql?) "EXEC FRUITP" "CALL FRUITP()")]
                             {:multi-rs true})
              zero-updates [{:next.jdbc/update-count 0}]]
          (cond (postgres?) ; does not support multiple result sets yet
                (do
                  (is (= 1 (count multi-rs)))
                  (is (= zero-updates (first multi-rs))))
                (hsqldb?)
                (do
                  (is (= 3 (count multi-rs)))
                  (is (= zero-updates (first multi-rs))))
                (mysql?)
                (do
                  (is (= 3 (count multi-rs)))
                  (is (= zero-updates (last multi-rs))))
                :else
                (is (= 2 (count multi-rs)))))
        (catch Throwable t
          (println 'call-proc (:dbtype (db)) (ex-message t) (some-> t (ex-cause) (ex-message))))))))
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
  "Type annotations for the base Clojure distribution."
  #?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
  (:require [clojure.core :as cc]
            [typed.clojure :as t]
            #?(:clj [typed.ann-macros.clojure :as macros])
            #?(:clj typed.ann.clojure.jvm) ;; jvm annotations
            #?(:clj clojure.core.typed))
  #?(:clj
     (:import (clojure.lang PersistentHashSet PersistentList
                            APersistentMap #_IPersistentCollection
                            #_ITransientSet
                            IRef)
              (java.util Comparator Collection))))

cc/rand [(t/? t/Num) :-> t/Num]
cc/rand-int [t/Int :-> t/Int]
cc/ex-info (t/IFn [(t/Nilable t/Str) (t/Map t/Any t/Any) :-> t/ExInfo]
                  [(t/Nilable t/Str) (t/Map t/Any t/Any) (t/? #?(:clj (t/Nilable Throwable) :cljs t/Any)) :-> t/ExInfo])
cc/ex-data (t/IFn [t/ExInfo :-> (t/Map t/Any t/Any)]
                  [t/Any :-> (t/Nilable (t/Map t/Any t/Any))])
cc/ex-message [t/Any :-> (t/Nilable t/Str)]
cc/ex-cause [t/Any :-> #?(:clj (t/Nilable Throwable) :cljs t/Any)]
fluree/db
(ns fluree.db.json-ld.api-test
  (:require #?(:clj  [clojure.test :refer [deftest is testing]]
               :cljs [cljs.test :refer-macros [deftest is testing async]])
            #?@(:cljs [[clojure.core.async :refer [go <!]]
                       [clojure.core.async.interop :refer [<p!]]])
            [fluree.db.did :as did]
            [fluree.db.dbproto :as dbproto]
            [fluree.db.json-ld.api :as fluree]
            [fluree.db.query.range :as query-range]
            [fluree.db.test-utils :as test-utils]
            [fluree.db.util.async :refer [<?? <?]]
            [fluree.db.util.context :as ctx-util]
            [fluree.db.util.core :as util]
            #?(:clj  [test-with-files.tools :refer [with-tmp-dir]
                      :as twf]
               :cljs [test-with-files.tools :as-alias twf])))

               (is (= flake-total
                      (:fuel response))
                   "Reports fuel for all the generated flakes")))
           (testing "without the `:meta` option"
             (let [response @(fluree/stage db0 {"@context" ["https://ns.flur.ee"
                                                            test-utils/default-context
                                                            {:ex "http://example.org/ns/"}]
                                                "insert"   test-utils/people})]
               (is (nil? (:fuel response))
                   "Returns no fuel")))
           (testing "short-circuits if request fuel exhausted"
             (let [response @(fluree/stage db0 {"@context" ["https://ns.flur.ee"
                                                            test-utils/default-context
                                                            {:ex "http://example.org/ns/"}]
                                                "insert"   test-utils/people}
                                           {:maxFuel 1})]
               (is (re-find #"Fuel limit exceeded"
                            (-> response ex-cause ex-message))))))
         (testing "queries"
           (let [db          @(fluree/stage db0 {"@context" ["https://ns.flur.ee"
                                                             test-utils/default-context
                                                             {:ex "http://example.org/ns/"}]
                                                 "insert"   test-utils/people})
                 flake-total (-> db :stats :flakes)
                 query       {:context test-utils/default-context
                              :select  '[?s ?p ?o]
                              :where   '{:id ?s, ?p ?o}}]
             (testing "queries not returning metadata"
               (let [sut @(fluree/query db query)]
                 (is (nil? (:fuel sut))
                     "Reports no fuel")))
             (testing "queries returning metadata"
               (let [query* (assoc-in query [:opts :meta] true)
                     sut    @(fluree/query db query*)]
                 (is (= (dec flake-total) (:fuel sut))
                     "Reports that all flakes were traversed"))))
           (testing "short-circuits if request fuel exhausted"
             (let [query   {:context test-utils/default-context
                            :select  '[?s ?p ?o]
                            :where   '{:id ?s
                                       ?p  ?o}
                            :opts    {:max-fuel 1}}
                   db      @(fluree/stage db0 {"@context" ["https://ns.flur.ee"
                                                           test-utils/default-context
                                                           {:ex "http://example.org/ns/"}]
                                               "insert" test-utils/people})
                   results @(fluree/query db query)]
               (is (util/exception? results))
               (is (re-find #"Fuel limit exceeded"
                            (-> results ex-cause ex-message))))))))
     :cljs
     (async done
       (go
         (testing "fuel tracking"
           (let [conn   (<! (test-utils/create-conn))
                 ledger (<p! (fluree/create conn "test/fuel-tracking"))
                 db0    (fluree/db ledger)]
             (testing "transactions"
               (testing "with the `:meta` option"
                 (let [response    (<p! (fluree/stage db0 {"@context" ["https://ns.flur.ee"
                                                                       test-utils/default-context
                                                                       {:ex "http://example.org/ns/"}]
                                                           "insert"   test-utils/people} {:meta true}))
                       db          (:result response)
                       flake-total (- (-> db :stats :flakes)
                                      (-> db0 :stats :flakes))]
                   (is (= flake-total (:fuel response))
                       "Reports fuel for all the generated flakes")))
               (testing "without the `:meta` option"
                 (let [response (<p! (fluree/stage db0 {"@context" ["https://ns.flur.ee"
                                                                    test-utils/default-context
                                                                    {:ex "http://example.org/ns/"}]
                                                        "insert"   test-utils/people}))]
                   (is (nil? (:fuel response))
                       "Returns no fuel")))
               (testing "short-circuits if request fuel exhausted"
                 (let [response (try
                                  (<p! (fluree/stage db0 {"@context" ["https://ns.flur.ee"
                                                                      test-utils/default-context
                                                                      {:ex "http://example.org/ns/"}]
                                                          "insert"   test-utils/people}
                                                     {:maxFuel 1}))
                                  (catch :default e (ex-cause e)))]
                   (is (re-find #"Fuel limit exceeded"
                                (-> response ex-cause ex-message))))))
             (testing "queries"
               (let [db          (<p! (fluree/stage db0 {"@context" ["https://ns.flur.ee"
                                                                     test-utils/default-context
                                                                     {:ex "http://example.org/ns/"}]
                                                         "insert"   test-utils/people}))
                     flake-total (-> db :stats :flakes)
                     query       {:context [test-utils/default-context
                                            {:ex "http://example.org/ns/"}]
                                  :select '[?s ?p ?o]
                                  :where  '{:id ?s
                                            ?p  ?o}}]
                 (testing "queries not returning metadata"
                   (let [sut (<p! (fluree/query db query))]
                     (is (nil? (:fuel sut))
                         "Reports no fuel")))
                 (testing "queries returning metadata"
                   (let [query* (assoc-in query [:opts :meta] true)
                         sut    (<p! (fluree/query db query*))]
                     (is (= (dec flake-total) (:fuel sut))
                         "Reports that all flakes were traversed"))))
               (testing "short-circuits if request fuel exhausted"
                 (let [query   {:context [test-utils/default-context
                                          {:ex "http://example.org/ns/"}]
                                :select '[?s ?p ?o]
                                :where  '{:id ?s
                                          ?p  ?o}
                                :opts   {:max-fuel 1}}
                       db      (<p! (fluree/stage db0 {"@context" ["https://ns.flur.ee"
                                                                   test-utils/default-context
                                                                   {:ex "http://example.org/ns/"}]
                                                       "insert"   test-utils/people}))
                       results (try
                                 (<p! (fluree/query db query))
                                 (catch :default e (ex-cause e)))]
                   (is (util/exception? results))
                   (is (re-find #"Fuel limit exceeded"
                                (-> results ex-cause ex-message))))))))
         (done)))))

       (is (= "SHACL PropertyShape exception - sh:maxCount of 1 lower than actual count of 2."
              (ex-message db4)))
athos/kitchen-async
(ns kitchen-async.promise.from-channel-test
  (:require [clojure.core.async :as a]
            [clojure.test :refer [deftest is async]]
            [kitchen-async.promise :as p]
            kitchen-async.promise.from-channel))

(deftest catch*-from-chan-test
  (async done
         (let [msg "something wrong has happened!!"
               ch (a/chan)]
           (js/setTimeout #(a/put! ch (ex-info msg {})) 0)
           (p/catch* ch
                     (fn [e]
                       (is (= msg (ex-message e)))
                       (done))))))
fluree/ledger
(ns fluree.db.ledger.docs.query.block-query
  (:require [clojure.test :refer :all]
            [fluree.db.test-helpers :as test]
            [fluree.db.ledger.docs.getting-started.basic-schema :as basic]
            [fluree.db.api :as fdb]
            [clojure.core.async :as async]
            [clojure.string :as str]))

(deftest query-single-block-with-ISO-string
  (testing "Select single block with ISO-8601 wall clock time"
    (let [query {:block "2017-11-14T20:59:36.097Z"}
          res   (try (async/<!! (fdb/block-query-async (basic/get-conn) test/ledger-chat query))
                     (catch Exception e e))]
      (is (= "There is no data as of 1510693176097" (ex-message res))))))

(deftest query-single-block-with-duration
  (testing "Select single block with duration string"
    (let [query {:block "PT1H"}
          res   (try (async/<!! (fdb/block-query-async (basic/get-conn) test/ledger-chat query))
                     (catch Exception e e))]
      (is (str/includes? (ex-message res) "There is no data as of ")))))