Use ereport instead of elog, make error handling consistent.