Skip to content

Error message improvements

marick edited this page Jul 29, 2011 · 4 revisions

One of the things I don't like about Clojure is that syntax or semantic errors are met by "Argh! Loser! Here's 3000 lines of stack trace." Currently, Midje follows in that tradition, but I'd like Midje's parser/translator to respond with something more helpful.

(This has been a pet peeve of mine for a long time.)

So: if you make a mistake typing a Midje form, and you had to puzzle to figure out what you did wrong, add the form here, explain what was wrong, and perhaps suggest the error message that would have helped you.


(fact (disassemble-folded original => [original])) ; typo
(fact (disassemble-folded original) => [original]) ; correct

Perhaps some message complaining that an => was observed in an odd place? But will have to take care not to break a zillion of Midje's own tests. Later: As far as I can tell, it would be very hard, if not impossible, to avoid giving false warnings


This makes sense:

(fact (f 3) => zero?)

Because of that, I often find myself putting checkers on the right side of prerequisites:

(fact 
   (f 3) => zero?)
   (provided
      (g 3) => zero?))

That doesn't do what I expect. It should be

     (zero? (g 3)) => true

But, once again, the problem is that sometimes you would want a prerequisite to return a function. (Mark ---that case with exactly? Only complain about checkers on the right-hand side?)


(defn f [n])
(unfinished g)

(fact
  (let [something 'some-value]
    (f [3]) => 3
    (against-background (g 3) => 3))) ;; incorrectly within the let body instead of at top level

Error message is "This doesn't look like part of a background: [midje.semi-sweet/expect (g 3) => 3 :position (midje.util.file-position/line-number-known 1)]" Which is not as helpful as it could be.

Clone this wiki locally