Properly return errors from scans and queries