diff --git a/sdk/ml/azure-ai-ml/azure/ai/ml/_schema/core/fields.py b/sdk/ml/azure-ai-ml/azure/ai/ml/_schema/core/fields.py index fd7956b85bb0..28147fac2875 100644 --- a/sdk/ml/azure-ai-ml/azure/ai/ml/_schema/core/fields.py +++ b/sdk/ml/azure-ai-ml/azure/ai/ml/_schema/core/fields.py @@ -369,7 +369,10 @@ def _deserialize(self, value, attr, data, **kwargs): if not path.is_absolute(): path = base_path / path path.resolve() - data = load_file(path) + try: + data = load_file(path) + except (FileNotFoundError, OSError) as e: + raise ValidationError(f"No such file or directory: {path}") from e return data raise ValidationError(f"Not supporting non file for {attr}") diff --git a/sdk/ml/azure-ai-ml/tests/schedule/unittests/test_schedule_schema.py b/sdk/ml/azure-ai-ml/tests/schedule/unittests/test_schedule_schema.py index 2bf677c8503a..3fe72131d613 100644 --- a/sdk/ml/azure-ai-ml/tests/schedule/unittests/test_schedule_schema.py +++ b/sdk/ml/azure-ai-ml/tests/schedule/unittests/test_schedule_schema.py @@ -157,3 +157,13 @@ def test_load_invalid_schedule_missing_type(self): with pytest.raises(ValidationError) as e: load_schedule(test_path) assert "'type' must be specified when scheduling a remote job with updates." in e.value.messages[0] + + def test_load_schedule_with_missing_create_job_file(self): + test_path = "./tests/test_configs/schedule/invalid/hello_cron_schedule_with_missing_job_file.yml" + with pytest.raises(ValidationError) as e: + load_schedule(test_path) + error_message = str(e.value) + assert "No such file or directory:" in error_message + assert "missing_pipeline.yml" in error_message + assert "In order to specify an existing jobs" not in error_message + assert "Not supporting non file for create_job" not in error_message diff --git a/sdk/ml/azure-ai-ml/tests/test_configs/schedule/invalid/hello_cron_schedule_with_missing_job_file.yml b/sdk/ml/azure-ai-ml/tests/test_configs/schedule/invalid/hello_cron_schedule_with_missing_job_file.yml new file mode 100644 index 000000000000..09f9fc80f952 --- /dev/null +++ b/sdk/ml/azure-ai-ml/tests/test_configs/schedule/invalid/hello_cron_schedule_with_missing_job_file.yml @@ -0,0 +1,11 @@ +$schema: http://azureml/sdk-2-0/Schedule.json +name: weekly_retrain_2022_missing_file +display_name: weekly retrain schedule +description: a weekly retrain schedule + +trigger: + type: cron + expression: "15 10 * * 1" + start_time: "2022-03-10T10:15:00" + +create_job: ./missing_pipeline.yml