When refactoring code, it often happens that it breaks in odd places. Additionally, it may not result in a nice error with a nice stacktrace that we can follow and find the offending place. Instead, we get odd data, odd-looking output, and it leaves us in the blue.
One way to approach this contracts. In Clojure(Script) they’re simply called pre/post conditions, and we can specify them when defining a function with
defn form. Whenever the function is called, and the input or output doesn’t satisfy the contract, an assertion error is thrown, and we can inspect the stacktrace. Continue reading “Catching errors with ClojureScript contracts”