improve logging of query.py errors