Skip to content

fix: auto-detect non-TTY stdin to prevent segfault in edit, move, and delete#980

Open
steven-range wants to merge 2 commits intoankitpokhrel:mainfrom
steven-range:fix/edit-non-tty-segfault
Open

fix: auto-detect non-TTY stdin to prevent segfault in edit, move, and delete#980
steven-range wants to merge 2 commits intoankitpokhrel:mainfrom
steven-range:fix/edit-non-tty-segfault

Conversation

@steven-range
Copy link
Copy Markdown

@steven-range steven-range commented Apr 10, 2026

What does this PR solve?

Several commands panic with a segfault in the survey library when stdin is not a terminal (e.g. piped input, CI pipelines, scripted agents). The crash occurs because the survey library assumes interactive TTY input.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x2 pc=0x1034a8018]

goroutine 1 [running]:
github.com/AlecAivazis/survey/v2/terminal.(*Cursor).MoveNextLine(...)

issue create and epic create already handle this case by checking cmdutil.StdinHasData() and implicitly setting noInput=true when stdin is not a TTY. This PR applies the same pattern to three other commands:

  • issue edit: implicitly sets noInput=true when stdin is not a TTY (matching issue create behavior)
  • issue move: errors with a clear message when required args (issue key, desired state) are missing in non-TTY context
  • issue delete: errors with a clear message when issue key arg is missing in non-TTY context

How to test?

Before this fix:

# Segfaults
echo "" | jira issue edit ISSUE-1 --custom story-point-estimate=1

# Segfaults (if args missing)
echo "" | jira issue move
echo "" | jira issue delete

After this fix:

# Works — implicitly uses --no-input behavior
echo "" | jira issue edit ISSUE-1 --custom story-point-estimate=1

# Also works — agents/CI calling without a TTY no longer need --no-input
jira issue edit ISSUE-1 --custom story-point-estimate=1  # in non-TTY context

# Clear error instead of segfault
echo "" | jira issue move
# Error: ISSUE-KEY argument is required in non-interactive mode

echo "" | jira issue delete
# Error: ISSUE-KEY argument is required in non-interactive mode

Checklist

  • I have added/updated enough tests related to my changes.
  • I have also manually checked and verified that my changes fix the issue and doesn't break any other functionalities.
  • My changes are backwards compatible.

Note: No test files exist for internal/cmd/issue/edit/, move/, or delete/ (consistent with the rest of the cmd layer). Changes are minimal guards matching the existing pattern in issue create.

steven-range and others added 2 commits April 10, 2026 09:23
`issue edit` panics with a segfault in the survey library when stdin
is not a terminal (e.g. piped input, CI, scripted agents) because
survey assumes interactive TTY input.

`issue create` and `epic create` already handle this by checking
`cmdutil.StdinHasData()` and implicitly setting noInput=true.
Apply the same guard to `issue edit` for consistency.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Same pattern as the edit fix — these commands use survey prompts
for missing arguments but don't check for a TTY first. In non-TTY
contexts (CI, agents, scripts), this causes a segfault when the
required arguments aren't provided.

- issue move: guard setIssueKey and setDesiredState
- issue delete: guard setIssueKey

When stdin is not a terminal and required args are missing, fail
with a clear error message instead of crashing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@steven-range steven-range changed the title fix: auto-detect non-TTY stdin in issue edit to prevent segfault fix: auto-detect non-TTY stdin to prevent segfault in edit, move, and delete Apr 10, 2026
Comment on lines +63 to +65
if !params.noInput && cmdutil.StdinHasData() {
params.noInput = true
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless, I'm wrong it means this

Suggested change
if !params.noInput && cmdutil.StdinHasData() {
params.noInput = true
}
params.noInput = cmdutil.StdinHasData()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to blindly overwrite. If the user (or coding agent) sends --no-input, that should be retained regardless of cmdutil.StdinHasData(). There may be an argument to simplify to what you've proposed, since piping something could indicate programmatic usage, but I don't think we can guarantee that. Changing that would be more than a bug fix, which is the intended purpose here.

It could become params.noInput = params.noInput || cmdutil.StdinHasData(), but I think that obscures readability for no tangible benefit.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your detailed reply. You are right 😅👍

I missed the fact we don't want to reset noInput to false depending on the value of the stdin.

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.

2 participants