Switch to using an enum for errors so we can report out-of-memory