From 6a4c236a49f21e9e3d218a24965996a2734ffaa6 Mon Sep 17 00:00:00 2001 From: Matt Skelley Date: Fri, 10 Apr 2026 00:30:39 +0800 Subject: [PATCH] fs: always return promise from openAsBlob() Wrap path validation and blob creation in try/catch. Any synchronous errors become Promise rejections. Ensures the function always returns a Promise. Fixes: https://github.com/nodejs/node/issues/62418 --- lib/fs.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index a7b56ee86171e3..778eed95db6c7d 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -574,8 +574,12 @@ function openAsBlob(path, options = kEmptyObject) { // The underlying implementation here returns the Blob synchronously for now. // To give ourselves flexibility to maybe return the Blob asynchronously, // this API returns a Promise. - path = getValidatedPath(path); - return PromiseResolve(createBlobFromFilePath(path, { type })); + try { + path = getValidatedPath(path); + return PromiseResolve(createBlobFromFilePath(path, { type })); + } catch (error) { + return Promise.reject(error); + } } /**