log immediately before executing query, remove premature error return (was pointless and error-prone)