fix(oxfmt): Use tokio::stdin/out to handle WouldBlock error#17946
fix(oxfmt): Use tokio::stdin/out to handle WouldBlock error#17946
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull request overview
This PR refactors oxfmt to use async I/O with tokio for stdout/stderr operations to handle WouldBlock errors that can occur during pipe operations. The main changes involve converting synchronous print functions to async versions using tokio's I/O primitives.
Changes:
- Converted
run()methods inFormatRunnerandStdinRunnerto async functions - Replaced synchronous
print_and_flush()with asyncprint_stdout()andprint_stderr()functions using tokio I/O - Restructured
FormatRunner::run()to properly handle the async/sync boundary withDiagnosticService
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/oxfmt/Cargo.toml | Added tokio "io-util" and "io-std" features to support async I/O operations |
| apps/oxfmt/src/core/utils.rs | Replaced synchronous print_and_flush() with async print functions using tokio I/O primitives |
| apps/oxfmt/src/stdin/mod.rs | Converted StdinRunner::run() to async and updated to use new async print functions |
| apps/oxfmt/src/cli/format.rs | Converted FormatRunner::run() to async, restructured to collect diagnostic output before async I/O operations |
| apps/oxfmt/src/main.rs | Added await for async FormatRunner::run() call |
| apps/oxfmt/src/main_napi.rs | Added await for async StdinRunner::run() and FormatRunner::run() calls |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Fixes #17939, closes #17943
Node.js sets stdout/stderr to non-blocking mode. When
oxfmtis called vianapiand writes large output using Rust'sstd::io::stdout(), it fails withWouldBlockerror because std I/O expects blocking mode.To fix, use tokio's async I/O which properly handles non-blocking I/O by retrying on
WouldBlock.