Skip to content

Commit bc9bd02

Browse files
authored
structaccess.Get: handle nil earlier, improve error message (#3660)
1 parent 5718df2 commit bc9bd02

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

acceptance/bundle/resource_deps/missing_ingestion_definition/out.plan.direct-exp.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Error: cannot resolve "${resources.pipelines.foo.ingestion_definition.connection_name}": field not set: ingestion_definition.connection_name: cannot access key "connection_name" on invalid
1+
Error: cannot resolve "${resources.pipelines.foo.ingestion_definition.connection_name}": field not set: ingestion_definition: cannot access nil value
22

33
Error: cannot plan resources.pipelines.bar: dependency failed: resources.pipelines.foo
44

libs/structs/structaccess/get.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func Get(v any, path *structpath.PathNode) (any, error) {
3636

3737
cur := reflect.ValueOf(v)
3838
for _, node := range pathSegments {
39+
if node.DotStar() || node.BracketStar() {
40+
return nil, fmt.Errorf("wildcards not supported: %s", path.String())
41+
}
42+
3943
var ok bool
4044
cur, ok = deref(cur)
4145
if !ok {
@@ -55,10 +59,6 @@ func Get(v any, path *structpath.PathNode) (any, error) {
5559
continue
5660
}
5761

58-
if node.DotStar() || node.BracketStar() {
59-
return nil, fmt.Errorf("wildcards not supported: %s", path.String())
60-
}
61-
6262
key, ok := node.StringKey()
6363
if !ok {
6464
return nil, errors.New("unsupported path node type")
@@ -288,6 +288,8 @@ func isEmptyForOmitEmpty(v reflect.Value) bool {
288288
func deref(v reflect.Value) (reflect.Value, bool) {
289289
for {
290290
switch v.Kind() {
291+
case reflect.Invalid:
292+
return v, false
291293
case reflect.Pointer:
292294
if v.IsNil() {
293295
return reflect.Value{}, false

libs/structs/structaccess/get_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
"github.com/databricks/databricks-sdk-go/service/jobs"
8+
"github.com/databricks/databricks-sdk-go/service/pipelines"
89
"github.com/stretchr/testify/require"
910
)
1011

@@ -690,3 +691,12 @@ func TestGetJobSettings(t *testing.T) {
690691
testGet(t, &jobSettings, "tasks[0].run_job_task", &jobs.RunJobTask{})
691692
testGet(t, &jobSettings, "tasks[0].run_job_task.job_id", int64(0))
692693
}
694+
695+
func TestPipeline(t *testing.T) {
696+
p := pipelines.CreatePipeline{}
697+
698+
v, err := GetByString(&p, "ingestion_definition.connectin_name")
699+
require.Error(t, err)
700+
require.Equal(t, "ingestion_definition: cannot access nil value", err.Error())
701+
require.Nil(t, v)
702+
}

0 commit comments

Comments
 (0)