Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 215
Support multiple locations for diagnostics#1610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
4bedb547ab131f39b3eea14a200ab38034450b8fa54d1e2a03b8fc6183558a6d9b89025b94edd52c2d2e6ed74d01202bcc16072f6a6028589aedd3d2ca95a04beb8f9File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -524,6 +524,17 @@ func (r Root) GetLocation(path string) dyn.Location { | ||
| return v.Location() | ||
| } | ||
| // Get all locations of the configuration value at the specified path. We need both | ||
| // this function and it's singular version (GetLocation) because some diagnostics just need | ||
| // the primary location and some need all locations associated with a configuration value. | ||
| func (r Root) GetLocations(path string) []dyn.Location { | ||
shreyas-goenka marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| v, err := dyn.Get(r.value, path) | ||
| if err != nil { | ||
| return []dyn.Location{} | ||
| } | ||
| return v.Locations() | ||
| } | ||
| // Value returns the dynamic configuration value of the root object. This value | ||
| // is the source of truth and is kept in sync with values in the typed configuration. | ||
| func (r Root) Value() dyn.Value { | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -6,6 +6,7 @@ import ( | ||
| "github.com/databricks/cli/bundle" | ||
| "github.com/databricks/cli/libs/diag" | ||
| "github.com/databricks/cli/libs/dyn" | ||
| ) | ||
| func JobClusterKeyDefined() bundle.ReadOnlyMutator { | ||
| @@ -41,8 +42,11 @@ func (v *jobClusterKeyDefined) Apply(ctx context.Context, rb bundle.ReadOnlyBund | ||
| diags = diags.Append(diag.Diagnostic{ | ||
| Severity: diag.Warning, | ||
| Summary: fmt.Sprintf("job_cluster_key %s is not defined", task.JobClusterKey), | ||
| Location: loc.Location(), | ||
| Path: loc.Path(), | ||
| // Show only the location where the job_cluster_key is defined. | ||
| // Other associated locations are not relevant since they are | ||
| // overridden during merging. | ||
| Locations: []dyn.Location{loc.Location()}, | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eventually I'll followup with a PR to show warnings when scalar configuration is being overridden. | ||
| Path: loc.Path(), | ||
| }) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,6 +7,7 @@ import ( | ||
| "github.com/databricks/cli/bundle" | ||
| "github.com/databricks/cli/libs/diag" | ||
| "github.com/databricks/cli/libs/dyn" | ||
| "github.com/databricks/cli/libs/fileset" | ||
| "golang.org/x/sync/errgroup" | ||
| ) | ||
| @@ -64,10 +65,10 @@ func checkPatterns(patterns []string, path string, rb bundle.ReadOnlyBundle) (di | ||
| loc := location{path: fmt.Sprintf("%s[%d]", path, index), rb: rb} | ||
| mu.Lock() | ||
| diags = diags.Append(diag.Diagnostic{ | ||
| Severity: diag.Warning, | ||
| Summary: fmt.Sprintf("Pattern %s does not match any files", p), | ||
| Location: loc.Location(), | ||
| Path: loc.Path(), | ||
| Severity: diag.Warning, | ||
| Summary: fmt.Sprintf("Pattern %s does not match any files", p), | ||
| Locations: []dyn.Location{loc.Location()}, | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does not matter if we use | ||
| Path: loc.Path(), | ||
| }) | ||
| mu.Unlock() | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -32,8 +32,8 @@ const errorTemplate = `{{ "Error" | red }}: {{ .Summary }} | ||
| {{- if .Path.String }} | ||
| {{ "at " }}{{ .Path.String | green }} | ||
| {{- end }} | ||
| {{- if .Location.File }} | ||
| {{ "in " }}{{ .Location.String | cyan }} | ||
| {{- range $index, $element := .Locations }} | ||
| {{ if eq $index 0 }}in {{else}} {{ end}}{{ $element.String | cyan }} | ||
| {{- end }} | ||
shreyas-goenka marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| {{- if .Detail }} | ||
| @@ -46,8 +46,8 @@ const warningTemplate = `{{ "Warning" | yellow }}: {{ .Summary }} | ||
| {{- if .Path.String }} | ||
| {{ "at " }}{{ .Path.String | green }} | ||
| {{- end }} | ||
| {{- if .Location.File }} | ||
| {{ "in " }}{{ .Location.String | cyan }} | ||
| {{- range $index, $element := .Locations }} | ||
| {{ if eq $index 0 }}in {{else}} {{ end}}{{ $element.String | cyan }} | ||
| {{- end }} | ||
| {{- if .Detail }} | ||
| @@ -141,12 +141,18 @@ func renderDiagnostics(out io.Writer, b *bundle.Bundle, diags diag.Diagnostics) | ||
| t = warningT | ||
| } | ||
| // Make file relative to bundle root | ||
| if d.Location.File != "" && b != nil { | ||
| out, err := filepath.Rel(b.RootPath, d.Location.File) | ||
| // if we can't relativize the path, just use path as-is | ||
| if err == nil { | ||
| d.Location.File = out | ||
| for i := range d.Locations { | ||
| if b == nil { | ||
| break | ||
| } | ||
| // Make location relative to bundle root | ||
| if d.Locations[i].File != "" { | ||
| out, err := filepath.Rel(b.RootPath, d.Locations[i].File) | ||
| // if we can't relativize the path, just use path as-is | ||
| if err == nil { | ||
| d.Locations[i].File = out | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we display multiple locations here since they are all relevant.