Finish refactor of error-handling paths in the reference-rewriting module.