               build-dir-url (str prev-build-dirs-url (:href (second target-link)))]
           (find-build-dir-revision build-dir-url))
         (let [target-link (nth build-dirs-links target-link-index) ; get the build directory and the revision from the link
-              build-dir-url (str build-dirs-url (:href (second target-link)))]
-          (find-build-dir-revision build-dir-url)))))
+              build-dir-url (str "https://archive.mozilla.org" (:href (second target-link)))]
+          ;; Try to obtain the revision for this build dir, or use the previous build dir if there's no revision in this one
+          ;; This is guaranteed to terminate since we recurse only on build dirs in a given month dir
+          (try
+            (find-build-dir-revision build-dir-url)
+            (catch AssertionError e ; Invalid build dir with no revision, just skip over it and go to the previous build dir link
+              (let [[_ year month day hour minute second] (re-find #"(\d{4})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-[^/]+/" build-dir-url)
+                    preceding-buildid (str year month day hour minute second)]
+                   (find-preceding-build-revision preceding-buildid channel))))))))
 
 (defn find-build-changeset
   "Finds the changesets corresponding to the build with buildid `buildid`, which is a URL for a page with a list of all new changesets that went into that build."

;; This library finds changesets given build dates (dates of the form YYYY-MM-DD)
;; or build IDs (exact build timestamps of the form YYYYMMDDhhmmss).
;;
;; Example: obtaining a link to the changesets for build date 2015-05-03:
;;
;;     (println (find-build-changeset (find-date-buildid "2015-05-03" "mozilla-central") "mozilla-central"))
;;
;; Example: obtaining a link to changesets for buildid 20150503030209
;;
;;     (println (find-build-changeset "20150503030209" "mozilla-central"))

(declare elements-by-tag-name)



        ;; Obtain a list of links to build directories in the desired channel
        build-dirs-url (format "https://archive.mozilla.org/pub/mozilla.org/firefox/nightly/%02d/%02d/" (:y p) (:m p))
        target (format "%04d-%02d-%02d-%02d-%02d-%02d-%s/" (:y p) (:m p) (:d p) (:hour p) (:min p) (:sec p) channel)
        response (tagsoup/parse build-dirs-url)
        links (elements-by-tag-name response :a)
        build-dirs-suffix (format "-%s/" channel)
