Skip to content

Preserve Promise semantics in result finally() - #2176

Open
Don-Yin wants to merge 1 commit into
postcss:mainfrom
Don-Yin:fix-finally-promise-semantics
Open

Don-Yin wants to merge 1 commit into
postcss:mainfrom
Don-Yin:fix-finally-promise-semantics

Conversation

@Don-Yin

@Don-Yin Don-Yin commented Oct 23, 2026 •

Copy link
Copy Markdown

LazyResult.finally() and NoWorkResult.finally() currently use then(cb, cb). A cleanup callback's return value replaces the Result, and a rejected processing promise becomes fulfilled if cleanup succeeds.

For example:

const postcss = require('postcss')
const lazy = postcss([]).process('a {}', { from: undefined })
await lazy.finally(() => 'ignored') // currently 'ignored', should be the Result

This delegates to the underlying promise's finally() to follow the standard Promise API documented in the types. Native Promise.finally() is available throughout the supported Node.js range, so no compatibility helper is needed.

The six regressions extend processor.test.ts and cover no plugins, synchronous plugins and asynchronous plugins. They check result/error identity, a callback with no arguments, and completion of asynchronous cleanup. All six fail on d1908579 and pass with the change.

Validation: env -u NO_COLOR pnpm test passes (727 tests, 100% line coverage, lint, declarations, version, integration and size checks); pnpm exec tsc --noEmit also passes. Windows and the other Node.js versions were not run locally.

Result and rejection preservation: zero of three processing modes pass on main, all three pass with the fix

Delegate to Promise.finally() so cleanup callbacks do not replace results
or turn processing errors into fulfilled promises.

Signed-off-by: Don Yin <Don_Yin@outlook.com>
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ae5ff586-cf1f-4819-83d8-c758754adad4
📥 Commits

Reviewing files that changed from the base of the PR and between d190857 and 42e1edc.

📒 Files selected for processing: 3
  • lib/lazy-result.js
  • lib/no-work-result.js
  • test/processor.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

LazyResult.finally and NoWorkResult.finally now use native promise finally. Tests cover cleanup completion and preservation of processing results and errors.

Changes: Promise finally behavior

Layer / File(s) Summary
Update finally behavior and tests
lib/lazy-result.js, lib/no-work-result.js, test/processor.test.ts
Both result classes delegate finally to the promise returned by async(). Tests cover fulfillment, asynchronous cleanup, ignored callback return values, and preservation of processing errors.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: ai

Merge Risk: ⚪ Minimal · up to 42e1e

The change appears ready to merge after normal checks; no actionable risk remains identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preserving native Promise semantics in result finally() methods.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3 files.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

This branch has not been deployed

No deployments
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.

1 participant