This is fine for this code review because I don't want to spend a lot of time improving it right now, but something to think about for the future: this is essentially the level of error reporting we had in SDF. And it kind of sucked. Let's do better, shall we?