scan_nextid: better error handling