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

NullPointerException #52

Closed
eerohele opened this issue Apr 25, 2019 · 4 comments
Closed

NullPointerException #52

eerohele opened this issue Apr 25, 2019 · 4 comments

Comments

@eerohele
Copy link

Trying to access this page returns a NullPointerException:

https://clojurians-log.clojureverse.org/clojurescript/2018-03-21

@eerohele
Copy link
Author

eerohele commented Apr 26, 2019

The comment for clojurians-log.views/channel-day-offset says:

Returns nil if the applying the offset goes out of bounds.

However, if the some call in the middle returns nil, the following calls throw an NPE.

Here's a sketch of a possible fix:

diff --git a/src/clj/clojurians_log/db/queries.clj b/src/clj/clojurians_log/db/queries.clj
index 6be8362..0a87ca1 100644
--- a/src/clj/clojurians_log/db/queries.clj
+++ b/src/clj/clojurians_log/db/queries.clj
@@ -82,7 +82,8 @@
               [?msg :message/day ?day]]
             db
             chan-name)
-       (sort-by first reverse-compare)))
+       (sort-by first reverse-compare)
+       (into [])))

 (defn channel [db name]
   (d/q '[:find (pull ?chan [*]) .
diff --git a/src/clj/clojurians_log/views.clj b/src/clj/clojurians_log/views.clj
index b8818f9..01b72d5 100644
--- a/src/clj/clojurians_log/views.clj
+++ b/src/clj/clojurians_log/views.clj
@@ -95,15 +95,14 @@
   `offset` positions away. Returns nil if the applying the offset goes out of
   bounds."
   [channel-days today offset]
-
-  (as-> channel-days $
-    (map vector (range) $)
-    (some (fn [[index [a-date msg-count]]] (when (and (= a-date today)
-                                                     (not (zero? msg-count)))
-                                            index)) $)
-    (+ $ offset)
-    (nth channel-days $ nil)
-    (first $)))
+  (some->> channel-days
+           (map vector (range))
+           (some (fn [[index [a-date msg-count]]] (when (and (= a-date today)
+                                                             (not (zero? msg-count)))
+                                                    index)))
+           (+ offset)
+           (get channel-days)
+           (first)))

 (defn- log-page-header [{:data/keys [channel date channel-days]}]
   [:div.header

@eerohele
Copy link
Author

eerohele commented Apr 26, 2019

On an unrelated note, this project is hit pretty hard by CLJ-2484. Trying to fire up a REPL ended out timeoutting even with pretty high :timeout values.

For posterity, here's what I did to get it into a state where I could debug the app:

--- a/project.clj
+++ b/project.clj
@@ -4,7 +4,7 @@
   :license {:name "Mozilla Public License 2.0"
             :url "https://www.mozilla.org/en-US/MPL/2.0/"}

-  :dependencies [[org.clojure/clojure "1.9.0"]
+  :dependencies [[org.clojure/clojure "1.10.1-beta2"]
                  [org.clojure/clojurescript "1.9.946" :scope "provided"]
                  [com.cognitect/transit-clj "0.8.300"]
                  [ring "1.6.3"]
@@ -122,8 +122,8 @@
   :profiles {:dev
              {:dependencies [[figwheel "0.5.15-SNAPSHOT"]
                              [figwheel-sidecar "0.5.15-SNAPSHOT"]
-                             [com.cemerick/piggieback "0.2.2"]
-                             [org.clojure/tools.nrepl "0.2.13"]
+                             [cider/piggieback "0.4.0"]
+                             [nrepl/nrepl "0.6.0"]
                              [lein-doo "0.1.8"]
                              [com.datomic/datomic-free "0.9.5656"]
                              [com.cemerick/pomegranate "1.0.0"]
@@ -138,7 +138,7 @@
                         [com.jakemccrary/lein-test-refresh "0.22.0"]]

               :source-paths ["dev"]
-              :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}}
+              :repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}}

              :production
              {:aot :all

@eerohele
Copy link
Author

Also, this issue seems to be a duplicate of #48.

@plexus
Copy link
Member

plexus commented Sep 11, 2019

This seems to be fixed

@plexus plexus closed this as completed Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants