Raises an error with a dynamic message if a validation check fails within a callback.