Hey Folks, I’ve created a component and just trying to eval it. But i keep getting NPE. Any clue about the root of this error? I am not passing any values, just want to eval the form.
Hard to say without a lot more detail
oh sorry
let me copy and paste my code here
(ns patrimoine.components.database
(:require [com.stuartsierra.component :as component]
[clojure.tools.logging :as log]
[monger.core :as monger]
[monger.collection :as monger-coll]
[monger.credentials :as monger-cred]
[patrimoine.protocols.database :as protocols.database]))
(def ^:const host "host")
(def ^:const port "port")
(def ^:const pwd "pwd")
(def ^:const database-name "database-name")
(def ^:const username "username")
(defn- connect-to-database [host port username database-name pwd]
(monger/connect-with-credentials host port (monger-cred/create username database-name pwd)))
(defrecord Database []
component/Lifecycle
(start [component]
(log/info ";; Starting Database")
(let [conn (connect-to-database host port username database-name pwd)]
(assoc component :connection conn)))
(stop [component]
(println ";; Stopping database")
(monger/disconnect (:connection component))
(assoc component :connection nil))
protocols.database/IDatabase
(insert-and-return! [component collection-name document]
(try
(monger-coll/insert-and-return (monger/get-db (:connection component)) collection-name document)
(catch Exeception e
(log/info e))))
(find-maps! [component collection-name query]
(try
(monger-coll/find-maps (monger/get-db (:connection component)) collection-name query)
(catch Exception e
(log/info e))))
(find-one-as-map! [component collection-name query]
(try
(monger-coll/find-one-as-map (monger/get-db (:connection component)) collection-name query)
(catch Exception e
(log/info e))))
(find-map-by-id! [component collection-name id]
(try
(monger-coll/find-map-by-id (monger/get-db (:connection component)) collection-name id)
(catch Exception e
(log/info e))))
(update-by-id! [component collection-name id query]
(try
(monger-coll/update-by-id (monger/get-db (:connection component)) collection-name id query)
(catch Exception e
(log/info e)))))
(defn new-database [] map->Database {})
Your new-database
function is missing ( .. )
around the call to map->Database {}
forms.
(defn new-database [] (map->Database {}))
is what it should be @quieterkali(although I wouldn't expect the protocol function calls to work at all, without that)
And, normally, sharing the stacktrace via a Gist or pastebin or something also helps people help you..
Thank you very much @seancorfield 😄 . Your solution fixed the issue. Next time I will put it in gist.
Have you watched Stu Halloway's talk "Debugging with the Scientific Method"?
No @seancorfield, but i going to watch it right now, thank you to mention it 🙂