       (into {} (map (fn [x] [x x]) dependencies))
     :else
       (throw (ex-info "Dependencies must be a map or vector"
-                      {:component component
+                      {:reason ::invalid-dependencies
+                       :component component
                        :dependencies dependencies})))))
 
 (defn dependency-graph

             (dep/graph)
             (select-keys system component-keys)))

(defn start-system
  "Recursively starts components in the system, in dependency order."
  [system component-keys]
  (let [graph (dependency-graph system component-keys)]
    (reduce (fn [system key]
              (let [component (get system key)]
                (try
                  (assoc system key
                         (start
                          (reduce-kv (fn [component dependency-key system-key]
                                       (assoc component dependency-key
                                              (get system system-key)))
                                     component
                                     (dependencies component))))
                  (catch Throwable t
                    (throw (ex-info "Error starting component"
                                    {:component component
                                     :system system}
                                    t))))))
            system
            (sort (dep/topo-comparator graph) component-keys))))


  [system component-keys]
  (let [graph (dependency-graph system component-keys)]
    (reduce (fn [system key]
              (assoc system key
                     (-> (get-component system key)
                         (stop-component system))))
            system
            (reverse (sort (dep/topo-comparator graph) component-keys)))))

