Detect command errors and return as error