Updated to use the makeInvalidError helper function.