node icon indicating copy to clipboard operation
node copied to clipboard

Fix: Add try/catch around stat() in Windows symlink logic

Open arnav-54 opened this issue 1 month ago β€’ 4 comments

πŸ›  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.

arnav-54 avatar Dec 01 '25 20:12 arnav-54

can you please review it @technoweenie @mojodna @bmizerany

arnav-54 avatar Dec 01 '25 20:12 arnav-54

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!

arnav-54 avatar Dec 02 '25 05:12 arnav-54

@aduh95 please review it.

arnav-54 avatar Dec 02 '25 17:12 arnav-54

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

arnav-54 avatar Dec 04 '25 17:12 arnav-54