Fix query() error handling.