mirror of
https://github.com/turbot/steampipe.git
synced 2025-12-19 18:12:43 -05:00
* Add test demonstrating bug #4788 - ClosePrompt panics with nil Adds TestClosePromptNilCancelPanic that reproduces the bug where ClosePrompt() panics with a nil pointer dereference when cancelPrompt is nil. This can happen if ClosePrompt is called before the prompt is fully initialized. Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix #4788: Add nil check before calling cancelPrompt Prevents panic in ClosePrompt() when cancelPrompt is nil. This can happen if ClosePrompt is called before the prompt is fully initialized. 🤖 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:
@@ -220,6 +220,31 @@ func TestClosePrompt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestClosePromptNilCancelPanic tests that ClosePrompt doesn't panic
|
||||
// when cancelPrompt is nil.
|
||||
//
|
||||
// This can happen if ClosePrompt is called before the prompt is fully
|
||||
// initialized or after manual nil assignment.
|
||||
//
|
||||
// Bug: #4788
|
||||
func TestClosePromptNilCancelPanic(t *testing.T) {
|
||||
// Create an InteractiveClient with nil cancelPrompt
|
||||
c := &InteractiveClient{
|
||||
cancelPrompt: nil,
|
||||
}
|
||||
|
||||
// This should not panic
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Errorf("ClosePrompt() panicked with nil cancelPrompt: %v", r)
|
||||
}
|
||||
}()
|
||||
|
||||
// Call ClosePrompt with nil cancelPrompt
|
||||
// This will panic without the fix
|
||||
c.ClosePrompt(AfterPromptCloseExit)
|
||||
}
|
||||
|
||||
// TestContextCancellationPropagation tests that parent context cancellation propagates
|
||||
func TestContextCancellationPropagation(t *testing.T) {
|
||||
c := &InteractiveClient{}
|
||||
|
||||
@@ -169,7 +169,10 @@ func (c *InteractiveClient) InteractivePrompt(parentContext context.Context) {
|
||||
// ClosePrompt cancels the running prompt, setting the action to take after close
|
||||
func (c *InteractiveClient) ClosePrompt(afterClose AfterPromptCloseAction) {
|
||||
c.afterClose = afterClose
|
||||
c.cancelPrompt()
|
||||
// only call cancelPrompt if it is not nil (to prevent panic)
|
||||
if c.cancelPrompt != nil {
|
||||
c.cancelPrompt()
|
||||
}
|
||||
}
|
||||
|
||||
// retrieve both the raw query result and a sanitised version in list form
|
||||
|
||||
Reference in New Issue
Block a user