general error handling, supports case where query returns nothing