diff --git a/examples/sdk/orchestrator/features/basic.go b/examples/sdk/orchestrator/features/basic.go index 019e6a53..83cdf84a 100644 --- a/examples/sdk/orchestrator/features/basic.go +++ b/examples/sdk/orchestrator/features/basic.go @@ -98,7 +98,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) hostname.DependsOn(health) diff --git a/examples/sdk/orchestrator/features/broadcast.go b/examples/sdk/orchestrator/features/broadcast.go index ba3bfaa2..01dbcbdf 100644 --- a/examples/sdk/orchestrator/features/broadcast.go +++ b/examples/sdk/orchestrator/features/broadcast.go @@ -88,7 +88,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/features/container-targeting.go b/examples/sdk/orchestrator/features/container-targeting.go index 5135cc47..2ffba082 100644 --- a/examples/sdk/orchestrator/features/container-targeting.go +++ b/examples/sdk/orchestrator/features/container-targeting.go @@ -129,7 +129,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) pull.DependsOn(preCleanup) @@ -160,7 +160,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) create.DependsOn(pull) @@ -187,7 +187,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) execHostname.DependsOn(create) @@ -212,7 +212,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) execUname.DependsOn(create) @@ -239,7 +239,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) execOS.DependsOn(create) @@ -264,7 +264,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) inspect.DependsOn(create) @@ -304,7 +304,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ).DependsOn(execHostname, execUname, execOS, inspect) diff --git a/examples/sdk/orchestrator/features/error-strategy.go b/examples/sdk/orchestrator/features/error-strategy.go index 87e36b72..af4cbe76 100644 --- a/examples/sdk/orchestrator/features/error-strategy.go +++ b/examples/sdk/orchestrator/features/error-strategy.go @@ -100,7 +100,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/features/guards.go b/examples/sdk/orchestrator/features/guards.go index d3c6bc42..30786c8f 100644 --- a/examples/sdk/orchestrator/features/guards.go +++ b/examples/sdk/orchestrator/features/guards.go @@ -99,7 +99,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) getHostname.DependsOn(health) diff --git a/examples/sdk/orchestrator/features/hooks.go b/examples/sdk/orchestrator/features/hooks.go index e840d1e4..5d65f1bb 100644 --- a/examples/sdk/orchestrator/features/hooks.go +++ b/examples/sdk/orchestrator/features/hooks.go @@ -141,7 +141,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) hostname.DependsOn(health) @@ -165,7 +165,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) disk.DependsOn(health) diff --git a/examples/sdk/orchestrator/features/only-if-changed.go b/examples/sdk/orchestrator/features/only-if-changed.go index 543a1aa2..846d6f62 100644 --- a/examples/sdk/orchestrator/features/only-if-changed.go +++ b/examples/sdk/orchestrator/features/only-if-changed.go @@ -83,7 +83,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/features/parallel.go b/examples/sdk/orchestrator/features/parallel.go index c63fdb10..bc94d944 100644 --- a/examples/sdk/orchestrator/features/parallel.go +++ b/examples/sdk/orchestrator/features/parallel.go @@ -113,7 +113,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) hostnameTask.DependsOn(health) @@ -137,7 +137,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diskTask.DependsOn(health) @@ -161,7 +161,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) memoryTask.DependsOn(health) diff --git a/examples/sdk/orchestrator/features/result-decode.go b/examples/sdk/orchestrator/features/result-decode.go index c6caf3a6..41aa7710 100644 --- a/examples/sdk/orchestrator/features/result-decode.go +++ b/examples/sdk/orchestrator/features/result-decode.go @@ -73,7 +73,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/features/task-func-results.go b/examples/sdk/orchestrator/features/task-func-results.go index 41d28e87..7aa11833 100644 --- a/examples/sdk/orchestrator/features/task-func-results.go +++ b/examples/sdk/orchestrator/features/task-func-results.go @@ -96,7 +96,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) getHostname.DependsOn(health) diff --git a/examples/sdk/orchestrator/features/task-func.go b/examples/sdk/orchestrator/features/task-func.go index 1c1dee53..2b509ea8 100644 --- a/examples/sdk/orchestrator/features/task-func.go +++ b/examples/sdk/orchestrator/features/task-func.go @@ -96,7 +96,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) hostname.DependsOn(health) diff --git a/examples/sdk/orchestrator/operations/command-exec.go b/examples/sdk/orchestrator/operations/command-exec.go index 0954a799..32bae2af 100644 --- a/examples/sdk/orchestrator/operations/command-exec.go +++ b/examples/sdk/orchestrator/operations/command-exec.go @@ -79,7 +79,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/command-shell.go b/examples/sdk/orchestrator/operations/command-shell.go index c5cb3755..7120e302 100644 --- a/examples/sdk/orchestrator/operations/command-shell.go +++ b/examples/sdk/orchestrator/operations/command-shell.go @@ -79,7 +79,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/docker-create.go b/examples/sdk/orchestrator/operations/docker-create.go index 2f322cdd..ee8f26e7 100644 --- a/examples/sdk/orchestrator/operations/docker-create.go +++ b/examples/sdk/orchestrator/operations/docker-create.go @@ -78,7 +78,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/docker-exec.go b/examples/sdk/orchestrator/operations/docker-exec.go index 2729be83..2f3dd802 100644 --- a/examples/sdk/orchestrator/operations/docker-exec.go +++ b/examples/sdk/orchestrator/operations/docker-exec.go @@ -78,7 +78,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/docker-inspect.go b/examples/sdk/orchestrator/operations/docker-inspect.go index 83f18737..35ecab40 100644 --- a/examples/sdk/orchestrator/operations/docker-inspect.go +++ b/examples/sdk/orchestrator/operations/docker-inspect.go @@ -76,7 +76,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/docker-list.go b/examples/sdk/orchestrator/operations/docker-list.go index cc31058e..8c126bea 100644 --- a/examples/sdk/orchestrator/operations/docker-list.go +++ b/examples/sdk/orchestrator/operations/docker-list.go @@ -76,7 +76,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/docker-pull.go b/examples/sdk/orchestrator/operations/docker-pull.go index 5ea0d41d..7923cd38 100644 --- a/examples/sdk/orchestrator/operations/docker-pull.go +++ b/examples/sdk/orchestrator/operations/docker-pull.go @@ -78,7 +78,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/docker-remove.go b/examples/sdk/orchestrator/operations/docker-remove.go index 51350ed3..62fd6f3f 100644 --- a/examples/sdk/orchestrator/operations/docker-remove.go +++ b/examples/sdk/orchestrator/operations/docker-remove.go @@ -76,7 +76,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/docker-start.go b/examples/sdk/orchestrator/operations/docker-start.go index f40a6ab7..d09791aa 100644 --- a/examples/sdk/orchestrator/operations/docker-start.go +++ b/examples/sdk/orchestrator/operations/docker-start.go @@ -76,7 +76,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/docker-stop.go b/examples/sdk/orchestrator/operations/docker-stop.go index 7b670766..8f5b5176 100644 --- a/examples/sdk/orchestrator/operations/docker-stop.go +++ b/examples/sdk/orchestrator/operations/docker-stop.go @@ -78,7 +78,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/network-dns-get.go b/examples/sdk/orchestrator/operations/network-dns-get.go index b41a9b36..13499eeb 100644 --- a/examples/sdk/orchestrator/operations/network-dns-get.go +++ b/examples/sdk/orchestrator/operations/network-dns-get.go @@ -76,7 +76,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/network-dns-update.go b/examples/sdk/orchestrator/operations/network-dns-update.go index 80489a1e..644c3b4a 100644 --- a/examples/sdk/orchestrator/operations/network-dns-update.go +++ b/examples/sdk/orchestrator/operations/network-dns-update.go @@ -79,7 +79,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/network-ping.go b/examples/sdk/orchestrator/operations/network-ping.go index dcc60d2a..a87e54a3 100644 --- a/examples/sdk/orchestrator/operations/network-ping.go +++ b/examples/sdk/orchestrator/operations/network-ping.go @@ -76,7 +76,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/node-disk.go b/examples/sdk/orchestrator/operations/node-disk.go index 24431e1a..ec3a51b8 100644 --- a/examples/sdk/orchestrator/operations/node-disk.go +++ b/examples/sdk/orchestrator/operations/node-disk.go @@ -76,7 +76,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/node-hostname.go b/examples/sdk/orchestrator/operations/node-hostname.go index e9880975..9aaa5411 100644 --- a/examples/sdk/orchestrator/operations/node-hostname.go +++ b/examples/sdk/orchestrator/operations/node-hostname.go @@ -76,7 +76,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/node-load.go b/examples/sdk/orchestrator/operations/node-load.go index a59465d8..99de5aa1 100644 --- a/examples/sdk/orchestrator/operations/node-load.go +++ b/examples/sdk/orchestrator/operations/node-load.go @@ -76,7 +76,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/node-memory.go b/examples/sdk/orchestrator/operations/node-memory.go index 0957538a..4f222a85 100644 --- a/examples/sdk/orchestrator/operations/node-memory.go +++ b/examples/sdk/orchestrator/operations/node-memory.go @@ -76,7 +76,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/node-status.go b/examples/sdk/orchestrator/operations/node-status.go index db5b71d9..b92d0e66 100644 --- a/examples/sdk/orchestrator/operations/node-status.go +++ b/examples/sdk/orchestrator/operations/node-status.go @@ -76,7 +76,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/examples/sdk/orchestrator/operations/node-uptime.go b/examples/sdk/orchestrator/operations/node-uptime.go index beba5273..86a584e5 100644 --- a/examples/sdk/orchestrator/operations/node-uptime.go +++ b/examples/sdk/orchestrator/operations/node-uptime.go @@ -76,7 +76,7 @@ func main() { Error: r.Error, } }, - ), nil + ) }, ) diff --git a/pkg/sdk/orchestrator/bridge.go b/pkg/sdk/orchestrator/bridge.go index 5f666a49..c1d6bfaa 100644 --- a/pkg/sdk/orchestrator/bridge.go +++ b/pkg/sdk/orchestrator/bridge.go @@ -2,6 +2,7 @@ package orchestrator import ( "encoding/json" + "fmt" client "github.com/retr0h/osapi/pkg/sdk/client" ) @@ -44,7 +45,7 @@ func CollectionResult[T any]( col client.Collection[T], rawJSON []byte, toHostResult func(T) HostResult, -) *Result { +) (*Result, error) { hostResults := make([]HostResult, 0, len(col.Results)) changed := false @@ -64,7 +65,9 @@ func CollectionResult[T any]( var data map[string]any if len(rawJSON) > 0 { - _ = jsonUnmarshalFn(rawJSON, &data) + if err := jsonUnmarshalFn(rawJSON, &data); err != nil { + return nil, fmt.Errorf("unmarshal response data: %w", err) + } } return &Result{ @@ -72,5 +75,5 @@ func CollectionResult[T any]( Changed: changed, Data: data, HostResults: hostResults, - } + }, nil } diff --git a/pkg/sdk/orchestrator/bridge_public_test.go b/pkg/sdk/orchestrator/bridge_public_test.go index cfa24d94..fb3d8c18 100644 --- a/pkg/sdk/orchestrator/bridge_public_test.go +++ b/pkg/sdk/orchestrator/bridge_public_test.go @@ -108,6 +108,7 @@ func (s *BridgePublicTestSuite) TestCollectionResult() { col client.Collection[client.HostnameResult] rawJSON []byte toHost func(client.HostnameResult) orchestrator.HostResult + expectErr bool validateFn func(result *orchestrator.Result) }{ { @@ -237,28 +238,35 @@ func (s *BridgePublicTestSuite) TestCollectionResult() { }, }, { - name: "invalid rawJSON leaves Result.Data nil", + name: "invalid rawJSON returns error", col: client.Collection[client.HostnameResult]{ Results: []client.HostnameResult{ {Hostname: "web-01"}, }, JobID: "job-bad", }, - rawJSON: []byte(`not valid json`), - toHost: mapper, - validateFn: func(result *orchestrator.Result) { - s.Nil(result.Data) - }, + rawJSON: []byte(`not valid json`), + toHost: mapper, + expectErr: true, }, } for _, tt := range tests { s.Run(tt.name, func() { - result := orchestrator.CollectionResult( + result, err := orchestrator.CollectionResult( tt.col, tt.rawJSON, tt.toHost, ) + + if tt.expectErr { + s.Error(err) + s.Nil(result) + + return + } + + s.NoError(err) s.Require().NotNil(result) tt.validateFn(result) })