fix: resolve infinite hang when formatter binary is not installed#39
Open
stevan-borus wants to merge 1 commit intocode-forge-io:mainfrom
Open
fix: resolve infinite hang when formatter binary is not installed#39stevan-borus wants to merge 1 commit intocode-forge-io:mainfrom
stevan-borus wants to merge 1 commit intocode-forge-io:mainfrom
Conversation
When `formatter: 'prettier'` or `formatter: 'biome'` is configured but the binary is not installed, `tinyexec` spawns a child process that immediately emits an `error` event (ENOENT). The previous code had an empty `error` handler and only resolved the promise on the `exit` event. Since Node does not emit `exit` after an ENOENT spawn error, the promise never resolved — causing `buildStart` to hang indefinitely and the Vite dev server to never start. Fix: wire the `error` handler to resolve the promise with the original (unformatted) content and log a warning, using a `settled` guard to prevent double-resolution when both `error` and `exit` fire. Add test that verifies the promise resolves (within 5s) when spawning a non-existent formatter binary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When
formatter: 'prettier'orformatter: 'biome'is configured but the binary is not installed (e.g. after migrating to a different formatter), the plugin'sbuildStarthook hangs indefinitely. The Vite dev server never starts — no error, no timeout, just a silent hang.This was introduced in #27 which moved formatter execution from direct API imports to
tinyexecchild processes to make formatters optional (#19). However, the error path wasn't wired up correctly.Root cause: In
lintFileContent(), when the formatter binary isn't found,tinyexecspawns a process that emits anerrorevent (ENOENT). Theerrorhandler was empty and the promise only resolved onexit, which Node does not emit after an ENOENT spawn error — so the promise hung forever.Fix: Wire the
errorhandler to resolve the promise with the original (unformatted) content and log a warning, using asettledguard to prevent double-resolution when botherrorandexitfire.Type of change
How Has This Been Tested?
Unit test: Added a test that spawns a non-existent binary via
tinyexecand asserts the promise resolves (within 5s) with the original content instead of hanging.Manual test steps:
iconsSpritesheet({ ..., formatter: 'prettier' })invite.config.tsprettieris not installed in the projectvite dev[icons-spritesheet] formatter "prettier" could not be started: spawn prettier ENOENT), spritesheet generated without formatting, dev server starts normallyReviewer checklist
Screenshots (if appropriate):
N/A — this is a CLI/build-time fix with no UI changes.
Questions (if appropriate):
N/A