Skip to content

fix(list): prevent nil pointer panic when spinner exits early - #2591

Merged
Andriy Knysh (aknysh) merged 2 commits into
cloudposse:mainfrom
MrZablah:fix/list-affected-nil-crash
Jun 10, 2026
Merged

Andriy Knysh (aknysh) merged 2 commits into
cloudposse:mainfrom
MrZablah:fix/list-affected-nil-crash

Conversation

@MrZablah

@MrZablah Miguel Zablah (MrZablah) commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

what

  • Fix atmos list affected panicking with a nil pointer dereference (result.Affected) when the spinner program exits before the background operation reports completion.
  • ExecWithSpinner / ExecWithSpinnerDynamic now wait for the operation goroutine to finish (<-goroutineDone) before returning.
  • New evaluateSpinnerResult / evaluateDynamicSpinnerResult helpers distinguish three outcomes: a spinner-level error, the operation's own error, or an interrupted/never-completed run (new
    ErrSpinnerOperationInterrupted).
  • ExecuteListAffectedCmd now defensively checks for a nil result and returns a wrapped ErrNilResult instead of dereferencing it.
  • Added a table-driven test (TestEvaluateSpinnerResults) covering both spinner result evaluators across all outcome combinations.

why

  • atmos list affected could crash with runtime error: invalid memory address or nil pointer dereference at pkg/list/list_affected.go:141. This happened when the bubbletea spinner's p.Run()
    returned before the background goroutine running getAffectedComponents finished — e.g. when many concurrent stderr writes (such as repeated ECR login messages, see fix(auth): deduplicate ECR, ECR Public, and EKS integrations to once per process #2564) corrupted the spinner's
    render loop, or when the user pressed ctrl+c.
  • The previous code only checked finalModel.err != nil and otherwise returned nil, so the caller proceeded with a nil result and panicked.
  • This makes the spinner helpers robust regardless of why the bubbletea program exits early, giving list affected (and any other caller of ExecWithSpinnerDynamic) a clear error instead of a
    crash.

references

Summary by CodeRabbit

  • Bug Fixes

    • Improved spinner completion and error handling for interrupted operations
    • Added detection and reporting of nil-result cases to avoid crashes
    • Standardized error propagation and messaging for spinner-related failures
  • Tests

    • Added tests covering spinner completion, interruption, nil results, unexpected outcomes, and error mapping

@MrZablah
Miguel Zablah (MrZablah) requested a review from a team as a code owner June 10, 2026 01:07
@atmos-pro

atmos-pro Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

@github-actions github-actions Bot added the size/m Medium size PR label Jun 10, 2026
@coderabbitai

coderabbitai Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: adf18094-3c5e-43d7-b71a-6e59e7feca5e

📥 Commits

Reviewing files that changed from the base of the PR and between c9640b6 and 8713abc.

📒 Files selected for processing (2)
  • pkg/ui/spinner/spinner.go
  • pkg/ui/spinner/spinner_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/ui/spinner/spinner_test.go

📝 Walkthrough

Walkthrough

Synchronizes spinner background goroutines with Bubble Tea program completion, adds sentinel errors for interrupted spinner and nil results, centralizes spinner post-run evaluation into helpers, and defends ExecuteListAffectedCmd against nil results. Tests cover the new evaluation logic.

Changes

Spinner synchronization and nil-result handling

Layer / File(s) Summary
Error sentinels for spinner states
errors/errors.go
Two new sentinel errors defined: ErrSpinnerOperationInterrupted and ErrNilResult.
Spinner goroutine synchronization and result evaluation
pkg/ui/spinner/spinner.go
ExecWithSpinner and ExecWithSpinnerDynamic wait for the background operation via a goroutineDone channel and delegate post-run logic to evaluateSpinnerResult / evaluateDynamicSpinnerResult, which wrap Bubble Tea errors and return interruption/nil/unexpected-type sentinels.
Spinner evaluation tests
pkg/ui/spinner/spinner_test.go
New table-driven test TestEvaluateSpinnerResults validates both evaluation helpers across program-run errors, operation errors, normal completion, interruption, nil final model, and unexpected model types.
Nil result defensive check in list_affected
pkg/list/list_affected.go
Adds an errUtils import and a guard in ExecuteListAffectedCmd to return a wrapped ErrNilResult when getAffectedComponents returns nil.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant ExecWithSpinner
  participant Background as BackgroundOperation
  participant BubbleTea as p.Run()
  participant Evaluator as evaluateSpinnerResult

  Caller->>ExecWithSpinner: call ExecWithSpinner(fn)
  ExecWithSpinner->>Background: spawn background goroutine
  Background->>ExecWithSpinner: send completion message / close goroutineDone
  ExecWithSpinner->>BubbleTea: p.Run() (blocks)
  BubbleTea->>ExecWithSpinner: return (on interrupt/completion)
  ExecWithSpinner->>ExecWithSpinner: wait for <-goroutineDone
  ExecWithSpinner->>Evaluator: evaluateSpinnerResult(finalModel, spinnerErr)
  Evaluator->>ExecWithSpinner: return result or sentinel error
  ExecWithSpinner->>Caller: return final result/error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • cloudposse/atmos#1047: Related spinner changes; both PRs touch the shared spinner execution/evaluation logic.

Suggested reviewers

  • aknysh
  • osterman
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main fix: preventing nil pointer panics in the list command when the spinner exits early.
Linked Issues check ✅ Passed The changes fully address issue #2590 requirements: adds goroutine synchronization with goroutineDone channels, introduces ErrSpinnerOperationInterrupted, adds defensive nil checks, and includes comprehensive test coverage.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the spinner synchronization issue and nil result handling; no extraneous modifications detected.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/ui/spinner/spinner.go`:
- Around line 71-78: The spinner error handling currently returns a plain
wrapped error and nil for unexpected model types; replace these with static
sentinel errors from errors/errors.go so callers can use errors.Is.
Specifically, where spinnerErr is checked (e.g., the block returning
fmt.Errorf("spinner error: %w", spinnerErr)), return a wrapped sentinel like
fmt.Errorf("%w: %v", errors.ErrSpinnerRunFailed, spinnerErr) (or create
ErrSpinnerRunFailed in errors/errors.go if missing). For the finalModel type
check (finalModel.(spinnerModel) failing), return a sentinel such as
errors.ErrUnexpectedSpinnerModel (wrap if you want context) instead of nil.
Apply the same change to the other occurrence handling (the second path
referenced) so both spinner-run failures and unexpected model types use static
errors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3901180f-ca30-4b4f-8184-0242496da710

📥 Commits

Reviewing files that changed from the base of the PR and between 12859a0 and c9640b6.

📒 Files selected for processing (4)
  • errors/errors.go
  • pkg/list/list_affected.go
  • pkg/ui/spinner/spinner.go
  • pkg/ui/spinner/spinner_test.go

Comment thread pkg/ui/spinner/spinner.go Resolved
@aknysh Andriy Knysh (aknysh) added the patch A minor, backward compatible change label Jun 10, 2026
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.70588% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.92%. Comparing base (12859a0) to head (8713abc).

Files with missing lines Patch % Lines
pkg/ui/spinner/spinner.go 68.75% 10 Missing ⚠️
pkg/list/list_affected.go 0.00% 2 Missing ⚠️

❌ Your patch check has failed because the patch coverage (64.70%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2591      +/-   ##
==========================================
+ Coverage   78.91%   78.92%   +0.01%     
==========================================
  Files        1207     1207              
  Lines      116438   116464      +26     
==========================================
+ Hits        91882    91921      +39     
+ Misses      19486    19471      -15     
- Partials     5070     5072       +2     
Flag Coverage Δ
unittests 78.92% <64.70%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
errors/errors.go 100.00% <ø> (ø)
pkg/list/list_affected.go 37.12% <0.00%> (-0.38%) ⬇️
pkg/ui/spinner/spinner.go 74.19% <68.75%> (+4.24%) ⬆️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aknysh Andriy Knysh (aknysh) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@aknysh
Andriy Knysh (aknysh) merged commit 3c1aba3 into cloudposse:main Jun 10, 2026
55 of 57 checks passed
@atmos-pro

atmos-pro Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

@github-actions

Copy link
Copy Markdown

These changes were released in v1.221.0.

@MrZablah
Miguel Zablah (MrZablah) deleted the fix/list-affected-nil-crash branch June 10, 2026 21:03
Igor Rodionov (goruha) added a commit that referenced this pull request Jun 11, 2026
…atmos into 1198-pact-consumer-contracts

* '1198-pact-consumer-contracts' of github.com:cloudposse/atmos:
  fix(ansible): forward `-- <args>` passthrough to ansible-playbook (#2594)
  fix(ci): use localhost endpoints in LocalStack demo to avoid DNS hangs (#2598)
  DAG follow-up: aggregate CI output for concurrent Terraform runs (#2577)
  fix(list): prevent nil pointer panic when spinner exits early (#2591)
  feat: describe affected evaluates all provisioned component sections (#2573)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch A minor, backward compatible change size/m Medium size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

atmos list affected panics with nil pointer dereference when the spinner exits

2 participants