Skip to content

Commit f1fbc8c

Browse files
Render full diagnostics in bundle run (#2844)
## Why `diags.Error()` only returns the`Details` in the diagnostic, and only returns `Summary` if the details are empty. We should render both In `bundle run` to be consistent with `bundle deploy`. At the same time, this PR also renders all `warnings` and `recommendations` if the user encounters an error. These warnings could have helpful context on what they need to fix in their configuration. ## Tests New acceptance test. Existing tests pass.
1 parent 8e9dfa3 commit f1fbc8c

File tree

7 files changed

+41
-19
lines changed

7 files changed

+41
-19
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bundle:
2+
name: run diagnostics
3+
4+
workspace:
5+
file_path: /Volumes/test
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
>>> [CLI] bundle run foo
3+
Error: workspace.file_path /Volumes/test starts with /Volumes. /Volumes can only be used with workspace.artifact_path.
4+
at workspace.file_path
5+
in databricks.yml:5:14
6+
7+
For more information, see https://docs.databricks.com/aws/en/dev-tools/bundles/settings#workspace
8+
9+
10+
Exit code: 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
trace $CLI bundle run foo

acceptance/bundle/run/inline-script/no-bundle/output.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
>>> [CLI] bundle run -- echo hello
33
Error: unable to locate bundle root: databricks.yml not found
44

5+
56
Exit code: 1

acceptance/bundle/run/inline-script/no-separator/output.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
>>> [CLI] bundle run echo hello
33
Error: unable to locate bundle root: databricks.yml not found
44

5+
56
Exit code: 1

cmd/bundle/deploy.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package bundle
33
import (
44
"context"
55
"fmt"
6+
"io"
67

78
"github.com/databricks/cli/bundle"
89
"github.com/databricks/cli/bundle/config/validate"
@@ -84,18 +85,21 @@ func newDeployCommand() *cobra.Command {
8485
}
8586
}
8687

87-
renderOpts := render.RenderOptions{RenderSummaryTable: false}
88-
err := render.RenderDiagnostics(cmd.OutOrStdout(), b, diags, renderOpts)
89-
if err != nil {
90-
return fmt.Errorf("failed to render output: %w", err)
91-
}
88+
return renderDiagnostics(cmd.OutOrStdout(), b, diags)
89+
}
90+
return cmd
91+
}
9292

93-
if diags.HasError() {
94-
return root.ErrAlreadyPrinted
95-
}
93+
func renderDiagnostics(w io.Writer, b *bundle.Bundle, diags diag.Diagnostics) error {
94+
renderOpts := render.RenderOptions{RenderSummaryTable: false}
95+
err := render.RenderDiagnostics(w, b, diags, renderOpts)
96+
if err != nil {
97+
return fmt.Errorf("failed to render output: %w", err)
98+
}
9699

97-
return nil
100+
if diags.HasError() {
101+
return root.ErrAlreadyPrinted
98102
}
99103

100-
return cmd
104+
return nil
101105
}

cmd/bundle/run.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ Example usage:
127127
cmd.RunE = func(cmd *cobra.Command, args []string) error {
128128
ctx := cmd.Context()
129129
b, diags := utils.ConfigureBundleWithVariables(cmd)
130-
if err := diags.Error(); err != nil {
131-
return diags.Error()
130+
if diags.HasError() {
131+
return renderDiagnostics(cmd.OutOrStdout(), b, diags)
132132
}
133133

134134
// If user runs the bundle run command as:
@@ -138,24 +138,24 @@ Example usage:
138138
return executeInline(cmd, args, b)
139139
}
140140

141-
diags = phases.Initialize(ctx, b)
142-
if err := diags.Error(); err != nil {
143-
return err
141+
diags = diags.Extend(phases.Initialize(ctx, b))
142+
if diags.HasError() {
143+
return renderDiagnostics(cmd.OutOrStdout(), b, diags)
144144
}
145145

146146
key, args, err := resolveRunArgument(ctx, b, args)
147147
if err != nil {
148148
return err
149149
}
150150

151-
diags = bundle.ApplySeq(ctx, b,
151+
diags = diags.Extend(bundle.ApplySeq(ctx, b,
152152
terraform.Interpolate(),
153153
terraform.Write(),
154154
terraform.StatePull(),
155155
terraform.Load(terraform.ErrorOnEmptyState),
156-
)
157-
if err := diags.Error(); err != nil {
158-
return err
156+
))
157+
if diags.HasError() {
158+
return renderDiagnostics(cmd.OutOrStdout(), b, diags)
159159
}
160160

161161
runner, err := keyToRunner(b, key)

0 commit comments

Comments
 (0)