             i++
 
         body = func(args...)
+        if body is undefined
+            throw new RqlDriverError "Annonymous function returned `undefined`. Did you forget a `return`?"
+
         argsArr = new MakeArray({}, argNums...)
         return super(optargs, argsArr, body)
 

                    datum.setType Datum.DatumType.R_STR
                    datum.setRStr @data
                else
                    throw new RqlDriverError "Unknown datum value `#{@data}`, did you forget a `return`?"
        term = new Term
        term.setType Term.TermType.DATUM
        term.setDatum datum

class RDBOp extends RDBVal
    constructor: (optargs, args...) ->
        self = super()
        self.args =
            for arg,i in args
                if arg isnt undefined
                    rethinkdb.expr arg
                else
                    throw new RqlDriverError "Argument #{i} to #{@st || @mt} may not be `undefined`."
        self.optargs = translateOptargs(optargs)
        return self

