From 3a3569e1a780dbeee0dc5e97359a3e0f07c8e0e7 Mon Sep 17 00:00:00 2001 From: Gleb Kanterov Date: Wed, 25 Sep 2024 10:26:17 +0200 Subject: [PATCH] Better messages --- bundle/config/validate/job_task_cluster_spec.go | 8 ++++++-- bundle/config/validate/job_task_cluster_spec_test.go | 12 +++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/bundle/config/validate/job_task_cluster_spec.go b/bundle/config/validate/job_task_cluster_spec.go index f175f2348..c119e6dc8 100644 --- a/bundle/config/validate/job_task_cluster_spec.go +++ b/bundle/config/validate/job_task_cluster_spec.go @@ -83,11 +83,15 @@ func validateJobTask(rb bundle.ReadOnlyBundle, task jobs.Task, taskPath dyn.Path // notebook tasks without cluster spec will use notebook environment } else { // path might be not very helpful, adding user-specified task key clarifies the context - detail := fmt.Sprintf("Task %q has a task type that requires a cluster or environment, but neither is specified", task.TaskKey) + detail := fmt.Sprintf( + "Task %q requires a cluster or an environment to run. Specify one of the following fields: %s", + task.TaskKey, + strings.Join(unspecified, ", "), + ) diags = diags.Append(diag.Diagnostic{ Severity: diag.Error, - Summary: fmt.Sprintf("One of the following fields must be set: %s", strings.Join(unspecified, ", ")), + Summary: fmt.Sprintf("Missing required cluster or environment settings"), Detail: detail, Locations: rb.Config().GetLocations(taskPath.String()), Paths: []dyn.Path{taskPath}, diff --git a/bundle/config/validate/job_task_cluster_spec_test.go b/bundle/config/validate/job_task_cluster_spec_test.go index 9145fb2d8..8f3bed839 100644 --- a/bundle/config/validate/job_task_cluster_spec_test.go +++ b/bundle/config/validate/job_task_cluster_spec_test.go @@ -13,7 +13,7 @@ import ( ) func TestJobTaskClusterSpec(t *testing.T) { - expectedSummary := "One of the following fields must be set: job_cluster_key, environment_key, existing_cluster_id, new_cluster" + expectedSummary := "Missing required cluster or environment settings" type testCase struct { name string @@ -143,8 +143,9 @@ func TestJobTaskClusterSpec(t *testing.T) { PythonWheelTask: &jobs.PythonWheelTask{}, TaskKey: "my_task", }, - errorPath: "resources.jobs.job1.tasks[0]", - errorDetail: "Task \"my_task\" has a task type that requires a cluster or environment, but neither is specified", + errorPath: "resources.jobs.job1.tasks[0]", + errorDetail: "Task \"my_task\" requires a cluster or an environment to run. Specify one of the " + + "following fields: job_cluster_key, environment_key, existing_cluster_id, new_cluster", errorSummary: expectedSummary, }, { @@ -157,8 +158,9 @@ func TestJobTaskClusterSpec(t *testing.T) { }, }, }, - errorPath: "resources.jobs.job1.tasks[0].for_each_task.task", - errorDetail: "Task \"my_task\" has a task type that requires a cluster or environment, but neither is specified", + errorPath: "resources.jobs.job1.tasks[0].for_each_task.task", + errorDetail: "Task \"my_task\" requires a cluster or an environment to run. Specify one of the " + + "following fields: job_cluster_key, environment_key, existing_cluster_id, new_cluster", errorSummary: expectedSummary, }, }