Skip to content

fix: resolve infinite hang when formatter binary is not installed#39

Open
stevan-borus wants to merge 1 commit intocode-forge-io:mainfrom
stevan-borus:fix/formatter-hang-on-missing-binary
Open

fix: resolve infinite hang when formatter binary is not installed#39
stevan-borus wants to merge 1 commit intocode-forge-io:mainfrom
stevan-borus:fix/formatter-hang-on-missing-binary

Conversation

@stevan-borus
Copy link
Copy Markdown

Description

When formatter: 'prettier' or formatter: 'biome' is configured but the binary is not installed (e.g. after migrating to a different formatter), the plugin's buildStart hook 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 tinyexec child 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, tinyexec spawns a process that emits an error event (ENOENT). The error handler was empty and the promise only resolved on exit, which Node does not emit after an ENOENT spawn error — so the promise hung forever.

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.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Algorithm update - updates algorithm documentation/questions/answers etc.
  • Other (please describe):

How Has This Been Tested?

  • Integration tests
  • Unit tests
  • Manual tests
  • No tests required

Unit test: Added a test that spawns a non-existent binary via tinyexec and asserts the promise resolves (within 5s) with the original content instead of hanging.

Manual test steps:

  1. Configure iconsSpritesheet({ ..., formatter: 'prettier' }) in vite.config.ts
  2. Ensure prettier is not installed in the project
  3. Run vite dev
  4. Before fix: dev server hangs indefinitely with zero output
  5. After fix: warning logged ([icons-spritesheet] formatter "prettier" could not be started: spawn prettier ENOENT), spritesheet generated without formatting, dev server starts normally

Reviewer checklist

  • Check if the UI is working as expected and is satisfactory
  • Check if the code is well documented
  • Check if the behavior is what is expected
  • Check if the code is well tested
  • Check if the code is readable and well formatted
  • Additional checks (document below if any)

Screenshots (if appropriate):

N/A — this is a CLI/build-time fix with no UI changes.

Questions (if appropriate):

N/A

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