Skip to content

Commit 4c0c06e

Browse files
authored
Fixed null pointer de-reference if artifacts missing fields (#3022)
## Changes Fixed null pointer de-reference if artifacts missing fields ## Why Fixes #3017 ## Tests Added regression test <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent a23be2d commit 4c0c06e

File tree

6 files changed

+48
-0
lines changed

6 files changed

+48
-0
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313

1414
### Bundles
1515
* Fix "bundle summary -o json" to render null values properly ([#2990](https://github.com/databricks/cli/pull/2990))
16+
* Fixed null pointer de-reference if artifacts missing fields ([#3022](https://github.com/databricks/cli/pull/3022))
1617

1718
### API Changes
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
bundle:
2+
name: nil_artifacts_test
3+
4+
artifacts:
5+
# This reproduces the issue from GitHub #3017
6+
# where artifacts have empty definitions (only comments)
7+
my_artifact:
8+
# build: <first_option_command>
9+
# path: <path>
10+
# build: <second_option_command>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
>>> [CLI] bundle validate
3+
Error: Artifact not properly configured
4+
in databricks.yml:7:15
5+
6+
please specify artifact properties
7+
8+
Name: nil_artifacts_test
9+
Target: default
10+
Workspace:
11+
User: [USERNAME]
12+
Path: /Workspace/Users/[USERNAME]/.bundle/nil_artifacts_test/default
13+
14+
Found 1 error
15+
16+
Exit code: 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
errcode trace $CLI bundle validate
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
RecordRequests = false
2+
3+
[[Repls]]
4+
Old = '\\\\'
5+
New = '/'
6+
7+
[[Repls]]
8+
Old = '\\'
9+
New = '/'

bundle/artifacts/prepare.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/databricks/cli/bundle/libraries"
1111
"github.com/databricks/cli/bundle/metrics"
1212
"github.com/databricks/cli/libs/diag"
13+
"github.com/databricks/cli/libs/dyn"
1314
"github.com/databricks/cli/libs/log"
1415
"github.com/databricks/cli/libs/python"
1516
"github.com/databricks/cli/libs/utils"
@@ -35,6 +36,16 @@ func (m *prepare) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics
3536

3637
for _, artifactName := range utils.SortedKeys(b.Config.Artifacts) {
3738
artifact := b.Config.Artifacts[artifactName]
39+
if artifact == nil {
40+
l := b.Config.GetLocation("artifacts." + artifactName)
41+
diags = append(diags, diag.Diagnostic{
42+
Severity: diag.Error,
43+
Summary: "Artifact not properly configured",
44+
Detail: "please specify artifact properties",
45+
Locations: []dyn.Location{l},
46+
})
47+
continue
48+
}
3849
b.Metrics.AddBoolValue(metrics.ArtifactBuildCommandIsSet, artifact.BuildCommand != "")
3950
b.Metrics.AddBoolValue(metrics.ArtifactFilesIsSet, len(artifact.Files) != 0)
4051

0 commit comments

Comments
 (0)