Fix #4713: Add nil check in initialiseSchemaAndTableSuggestions (#4879)

* Add test for #4713: initialiseSchemaAndTableSuggestions should handle nil client

* Fix #4713: Add nil check in initialiseSchemaAndTableSuggestions
This commit is contained in:
Nathan Wallace
2025-11-16 00:17:46 +08:00
committed by GitHub
parent 79ab1c9b69
commit 0d6cb1afad
2 changed files with 38 additions and 0 deletions

View File

@@ -44,6 +44,11 @@ func (c *InteractiveClient) initialiseSchemaAndTableSuggestions(connectionStateM
return
}
// check if client is nil to avoid panic
if c.client() == nil {
return
}
// unqualified table names
// use lookup to avoid dupes from dynamic plugins
// (this is needed as GetFirstSearchPathConnectionForPlugins will return ALL dynamic connections)

View File

@@ -0,0 +1,33 @@
package interactive
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/turbot/steampipe/v2/pkg/db/db_common"
"github.com/turbot/steampipe/v2/pkg/steampipeconfig"
)
// TestInitialiseSchemaAndTableSuggestions_NilClient tests that initialiseSchemaAndTableSuggestions
// handles a nil client gracefully without panicking.
// This is a regression test for bug #4713.
func TestInitialiseSchemaAndTableSuggestions_NilClient(t *testing.T) {
// Create an InteractiveClient with nil initData, which causes client() to return nil
c := &InteractiveClient{
initData: nil, // This will cause client() to return nil
suggestions: newAutocompleteSuggestions(),
// Set schemaMetadata to non-nil so we get past the early return on line 43
schemaMetadata: &db_common.SchemaMetadata{
Schemas: make(map[string]map[string]db_common.TableSchema),
TemporarySchemaName: "temp",
},
}
// Create an empty connection state map
connectionStateMap := steampipeconfig.ConnectionStateMap{}
// This should not panic - the function should handle nil client gracefully
assert.NotPanics(t, func() {
c.initialiseSchemaAndTableSuggestions(connectionStateMap)
})
}