Skip to content

Commit 50dd38f

Browse files
fix: Correctly validate backend_options configuration (#2182)
1 parent 817ebdd commit 50dd38f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

state/client.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,16 @@ func NewConnectedClient(ctx context.Context, backendOpts *plugin.BackendOptions)
5555
// The state client is guaranteed to be non-nil (it defaults to the NoOpClient).
5656
// You must call Close() on the returned Client object.
5757
func NewConnectedClientWithOptions(ctx context.Context, backendOpts *plugin.BackendOptions, connOpts ConnectionOptions, clOpts ClientOptions) (Client, error) {
58-
if backendOpts == nil {
58+
// backend_options missing or configured but empty
59+
if backendOpts == nil || (backendOpts.Connection == "" && backendOpts.TableName == "") {
5960
return &NoOpClient{}, nil
6061
}
6162

63+
// backend_options configured incorrectly, e.g. missing connection or table_name
64+
if backendOpts.Connection == "" || backendOpts.TableName == "" {
65+
return nil, fmt.Errorf("backend_options must contain both connection and table_name: %v", backendOpts)
66+
}
67+
6268
backendConn, err := grpc.NewClient(backendOpts.Connection,
6369
grpc.WithTransportCredentials(insecure.NewCredentials()),
6470
grpc.WithDefaultCallOptions(

0 commit comments

Comments
 (0)