Skip to content

Commit

Permalink
Log warnings to stderr for "bundle validate -o json"
Browse files Browse the repository at this point in the history
  • Loading branch information
denik committed Jan 9, 2025
1 parent a0455bc commit 1ce1050
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
15 changes: 15 additions & 0 deletions acceptance/bundle/override/job_tasks/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
>>> errcode $CLI bundle validate -o json -t development
Error: file ./test1.py not found


Exit code: 1
{
"name": "job",
Expand Down Expand Up @@ -36,6 +37,7 @@ Exit code: 1
>>> errcode $CLI bundle validate -o json -t staging
Error: file ./test1.py not found


Exit code: 1
{
"name": "job",
Expand Down Expand Up @@ -66,3 +68,16 @@ Exit code: 1
}
]
}

>>> errcode $CLI bundle validate -t staging
Error: file ./test1.py not found

Name: override_job_tasks
Target: staging
Workspace:
User: [email protected]
Path: /Workspace/Users/[email protected]/.bundle/override_job_tasks/staging

Found 1 error

Exit code: 1
1 change: 1 addition & 0 deletions acceptance/bundle/override/job_tasks/script
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
trace errcode $CLI bundle validate -o json -t development | jq .resources.jobs.foo
trace errcode $CLI bundle validate -o json -t staging | jq .resources.jobs.foo
trace errcode $CLI bundle validate -t staging
4 changes: 4 additions & 0 deletions acceptance/bundle/override/merge-string-map/output.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

>>> $CLI bundle validate -o json -t dev
Warning: expected map, found string
at resources.clusters.my_cluster
in databricks.yml:6:17

{
"clusters": {
"my_cluster": {
Expand Down
23 changes: 19 additions & 4 deletions cmd/bundle/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ import (
"github.com/databricks/cli/bundle/render"
"github.com/databricks/cli/cmd/bundle/utils"
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/flags"
"github.com/spf13/cobra"
)

func renderJsonOutput(cmd *cobra.Command, b *bundle.Bundle, diags diag.Diagnostics) error {
func renderJsonOutput(cmd *cobra.Command, b *bundle.Bundle) error {
buf, err := json.MarshalIndent(b.Config.Value().AsAny(), "", " ")
if err != nil {
return err
}
_, _ = cmd.OutOrStdout().Write(buf)
return diags.Error()
return nil
}

func newValidateCommand() *cobra.Command {
Expand Down Expand Up @@ -66,7 +65,23 @@ func newValidateCommand() *cobra.Command {

return nil
case flags.OutputJSON:
return renderJsonOutput(cmd, b, diags)
renderOpts := render.RenderOptions{RenderSummaryTable: false}
err1 := render.RenderDiagnostics(cmd.OutOrStderr(), b, diags, renderOpts)
err2 := renderJsonOutput(cmd, b)

if err2 != nil {
return err2
}

if err1 != nil {
return err1
}

if diags.HasError() {
return root.ErrAlreadyPrinted
}

return nil
default:
return fmt.Errorf("unknown output type %s", root.OutputType(cmd))
}
Expand Down

0 comments on commit 1ce1050

Please sign in to comment.