Fix: Add try/catch around stat() in Windows symlink logic
π Fix: Add defensive try/catch around stat() in Windows symlink logic
This PR adds a small defensive wrapper around the stat() call used during
symlink creation on Windows. In certain environments, stat() may throw
synchronously rather than returning an error, which can crash the Node.js
process. Catching this ensures the code fails safely instead of terminating.
Why this matters
-
Prevents rare but real crashes: handles synchronous
stat()throws. - Graceful fallback: falls back to the standard symlink creation path.
- Minimal, targeted change: only adds a simple try/catch and comment.
- Windows-specific: no impact on other platforms or code paths.
Summary
A small but meaningful defensive improvement that improves Windows stability while preserving existing behavior and keeping the change surface minimal.
can you please review it @technoweenie @mojodna @bmizerany
Hi, this PR adds a small defensive try/catch around stat() in the Windows symlink code path.
This avoids a rare synchronous crash when stat() throws on certain Windows setups.
Itβs a minimal change (just a try/catch) and falls back to default symlink behavior.
Whenever possible, could someone approve the workflows so CI can run? Thanks!
@aduh95 please review it.
@legendecas. "Added test case in test/parallel/test-fs-symlink-windows-error-handling.js that verifies the symlink creation handles stat() errors gracefully on Windows. The test creates a symlink with a relative target that would cause the internal stat(absoluteTarget) call to potentially fail, ensuring the try-catch block works as expected."