Update the error check for more precise error messages