Error handling in core.async

Played around using core.async in ClojureScript for coordinating async AJAX requests and app state updates. See this gist for more code and explanation.

(defrecord Controller [state router]
  view/ControllerProtocol
 
  (on-navigation [_ file-id]
    (go
      (try
        (chain
          (<?initialize-state! state)
          (<?set-current-file! state file-id router))
        
        (catch js/Object e
          (println "!!! ERROR - on-navigation - caught"
                   (if (channel-error? e)
                     (str "error from some channel, error data: " (channel-error-data e))
                     (str "js exception: " e)))))))
 
  (on-change-current-file [_ file-id]
    (go
      (try
        ; <? is needed to wait for result or raise an exception
        (<? (<?set-current-file! state file-id router))
 
        (catch js/Object e
          (.error js/console "on-change-current-file exception:" e))))))

There are two w…

There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.

C. A. R. Hoare