executeMetaquery error handling closes #4789 (#4834)

* 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:
Nathan Wallace
2025-11-16 12:00:19 -05:00
committed by GitHub
parent 189a1e38a2
commit bf3092396c
2 changed files with 26 additions and 1 deletions

View File

@@ -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)

View File

@@ -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)
}