exit with failure on query failure (improved)