Skip to content

Fix panic running plugin subcommands with nil context#1708

Open
xheggs wants to merge 1 commit into
stripe:masterfrom
xheggs:fix-plugin-subcommand-nil-context
Open

Fix panic running plugin subcommands with nil context#1708
xheggs wants to merge 1 commit into
stripe:masterfrom
xheggs:fix-plugin-subcommand-nil-context

Conversation

@xheggs

@xheggs xheggs commented Jun 23, 2026

Copy link
Copy Markdown

Summary

Every executed plugin subcommand under stripe projects (init, status, catalog, search, add, …) panics with cannot create context from nil parent instead of running, making the Projects plugin unusable.

runPluginCmd passes cmd.Context() into withSIGTERMCancel, but cmd.Context() is nil for the dynamically-registered plugin subcommand stubs, so context.WithCancel(nil) panics under Go 1.15+.

The help path in the same file already guards against this with SetContext(context.Background()); this PR applies the same guard to the execution path.

Fixes #1707.

Change

parentCtx := cmd.Context()
if parentCtx == nil {
	parentCtx = context.Background()
}
ctx := withSIGTERMCancel(parentCtx, func() { ... })

Reproduction

stripe plugin install projects        # v0.20.0
stripe login
stripe projects status                # panics

Stack trace:

panic: cannot create context from nil parent
context.WithCancel({0x0?, 0x0?})
github.com/stripe/stripe-cli/pkg/cmd.withSIGTERMCancel(...)   pkg/cmd/listen.go:223
github.com/stripe/stripe-cli/pkg/cmd.(*pluginTemplateCmd).runPluginCmd(...)   pkg/cmd/plugin_cmds.go:105
github.com/stripe/stripe-cli/pkg/cmd.addPluginSubcommandStubs.func1(...)   pkg/cmd/plugin_cmds.go:91

Testing

  • Reproduced the panic on v1.42.15 (Homebrew) and on a clean build of the tag.
  • Built from source with this change: stripe projects status / init / catalog now run normally instead of panicking.
  • go build ./... and gofmt clean.

Environment

  • stripe-cli v1.42.15 (also reproduced on v1.40.8)
  • projects plugin v0.20.0
  • macOS 26.2, arm64

stripe projects <subcommand> (init, status, catalog, ...) panics with
"cannot create context from nil parent": runPluginCmd passes cmd.Context()
into withSIGTERMCancel, but the context is nil for plugin subcommand stubs,
so context.WithCancel(nil) panics.

Default the parent context to context.Background() when nil, mirroring the
guard already used on the plugin help path.

Fixes stripe#1707
@cla-assistant

cla-assistant Bot commented Jun 23, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stripe projects <subcommand> panics: "cannot create context from nil parent" (nil ctx in runPluginCmd)

1 participant