avoid a crash and improve error reporting