Skip to content

Codex/fix nil stdin panic#4

Closed
steipete wants to merge 2 commits intobeeper:mainfrom
steipete:codex/fix-nil-stdin-panic
Closed

Codex/fix nil stdin panic#4
steipete wants to merge 2 commits intobeeper:mainfrom
steipete:codex/fix-nil-stdin-panic

Conversation

@steipete
Copy link

@steipete steipete commented Mar 8, 2026

Summary

Hi folks, my clanker found a bug, this is AI generated and solved my issue. Take it as a signal, I didn't spend time to investigate the architecture, just reporting this crash and a slop fix.

Fix a panic in embedFiles / flagOptions when the CLI is run from a captured subprocess with empty piped stdin.

In that case isInputPiped() is true, yaml.Unmarshal can leave bodyData as nil, and embedFiles(nil, ...) would panic via reflect.Value.Interface() on an invalid value.

Fix

  • guard invalid reflect.Value / nil input in embedFiles
  • guard invalid values in embedFilesValue

Tests

  • add regression coverage for embedFiles(nil, ...)
  • add regression coverage for flagOptions with empty piped stdin and no flags

Repro

The crash shows up in wrappers like Python subprocess.run(..., capture_output=True) when invoking commands such as:

beeper-desktop-cli messages search --account-id discordgo --chat-type single --query friend --limit 2 --format json

A temporary workaround is redirecting stdin from /dev/null, but this patch fixes the root cause.

@coderabbitai
Copy link

coderabbitai bot commented Mar 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a7fd9423-4edf-4498-a07f-5dd7db0d72f0

📥 Commits

Reviewing files that changed from the base of the PR and between 1de48f2 and 71d0ffc.

📒 Files selected for processing (2)
  • pkg/cmd/flagoptions.go
  • pkg/cmd/flagoptions_test.go
📜 Recent review details
🔇 Additional comments (2)
pkg/cmd/flagoptions.go (1)

43-59: Nice panic fix for invalid reflect.Value inputs.

These early returns cleanly short-circuit the empty-stdin/nil path before any Kind() or Interface() call can panic. The change is tight and keeps the normal embedding flow untouched.

pkg/cmd/flagoptions_test.go (1)

9-12: Good regression coverage for the reported crash path.

The added cases hit both the low-level nil input behavior and the real empty-piped-stdin flow in flagOptions, which makes this fix much harder to regress.

Also applies to: 217-269


📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced input validation to prevent errors when processing invalid values
  • Tests

    • Expanded test coverage for edge cases and nil input handling

Walkthrough

Adds early validity checks for invalid reflect.Value inputs in embedFiles and embedFilesValue functions to short-circuit processing. Extends test coverage with a new scenario for nil input and a test for empty piped stdin with no flags.

Changes

Cohort / File(s) Summary
Embed Files Validation
pkg/cmd/flagoptions.go
Adds early validity checks using reflect.Value.IsValid() in embedFiles and embedFilesValue to return early when input is invalid, preventing further processing.
Test Coverage
pkg/cmd/flagoptions_test.go
Adds imports for internal/apiquery and urfave/cli/v3, extends TestEmbedFiles with "nil input unchanged" scenario, and introduces TestFlagOptionsWithEmptyPipedStdinAndNoFlags to verify behavior with empty stdin and no flags.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Codex/fix nil stdin panic' directly addresses the main problem being fixed—a panic caused by nil stdin in the embedFiles/flagOptions functions.
Description check ✅ Passed The description clearly explains the bug (panic with nil stdin), the root cause, the fixes applied, and test coverage added, all directly related to the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@KishanBagaria
Copy link
Member

should be fixed by #3

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants