mirror of
https://github.com/turbot/steampipe.git
synced 2025-12-19 18:12:43 -05:00
* Add test for #4789: executeMetaquery panic instead of error Added TestExecuteMetaquery_NotInitialised to demonstrate the bug where executeMetaquery panics with "client is not initalised" instead of returning an error when called before initialization completes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix #4789: Return error instead of panic in executeMetaquery Replace panic("client is not initalised") with proper error return in executeMetaquery. This prevents unrecoverable crashes when the method is called before client initialization completes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -513,7 +513,7 @@ func (c *InteractiveClient) getQuery(ctx context.Context, line string) *modconfi
|
||||
func (c *InteractiveClient) executeMetaquery(ctx context.Context, query string) error {
|
||||
// the client must be initialised to get here
|
||||
if !c.isInitialised() {
|
||||
panic("client is not initalised")
|
||||
return fmt.Errorf("client is not initialised")
|
||||
}
|
||||
// validate the metaquery arguments
|
||||
validateResult := metaquery.Validate(query)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package interactive
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -630,3 +631,27 @@ func TestGetQueryInfo_FromDetection(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestExecuteMetaquery_NotInitialised tests that executeMetaquery returns
|
||||
// an error instead of panicking when the client is not initialized.
|
||||
//
|
||||
// Bug: #4789
|
||||
func TestExecuteMetaquery_NotInitialised(t *testing.T) {
|
||||
// Create an InteractiveClient that is not initialized
|
||||
c := &InteractiveClient{}
|
||||
c.initialisationComplete.Store(false)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Attempt to execute a metaquery before initialization
|
||||
// This should return an error, not panic
|
||||
err := c.executeMetaquery(ctx, ".inspect")
|
||||
|
||||
// We expect an error
|
||||
if err == nil {
|
||||
t.Error("Expected error when executing metaquery before initialization, but got nil")
|
||||
}
|
||||
|
||||
// The test passes if we get here without a panic
|
||||
t.Logf("Successfully received error instead of panic: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user