The usual Erlang controversy: crash or return an error here.  Notice how this is directly passed to apply_continuation above, which would end up in a continuation error. Also, the result of this function is sometimes directly passed to some folding functions with side effects quickly getting out of control. Consider throwing or letting it crash instead.