diff --git a/lib/internal/vfs/file_system.js b/lib/internal/vfs/file_system.js index ae38639582581b..7a473eed6728f0 100644 --- a/lib/internal/vfs/file_system.js +++ b/lib/internal/vfs/file_system.js @@ -143,7 +143,13 @@ class VirtualFileSystem { this[kMounted] = true; debug('mount %s', this[kMountPoint]); loadVfsSetup(); - registerVFS(this); + try { + registerVFS(this); + } catch (err) { + this[kMountPoint] = null; + this[kMounted] = false; + throw err; + } return this; } diff --git a/test/parallel/test-vfs-mount-errors.js b/test/parallel/test-vfs-mount-errors.js index 905f1c6d0683ab..371456eb609d34 100644 --- a/test/parallel/test-vfs-mount-errors.js +++ b/test/parallel/test-vfs-mount-errors.js @@ -16,6 +16,11 @@ const { vfsState } = require('internal/fs/utils'); const baseMountPoint = path.resolve('/tmp/vfs-mount-errors-' + process.pid); let mountCounter = 0; const nextMount = () => baseMountPoint + '-' + (mountCounter++); +function assertUnmounted(instance, mountPoint) { + assert.strictEqual(instance.mounted, false); + assert.strictEqual(instance.mountPoint, null); + assert.strictEqual(instance.shouldHandle(mountPoint), false); +} // EXDEV: rename across two different VFS instances { @@ -130,6 +135,7 @@ const nextMount = () => baseMountPoint + '-' + (mountCounter++); const b = vfs.create(); a.mount(parent); assert.throws(() => b.mount(child), { code: 'ERR_INVALID_STATE' }); + assertUnmounted(b, child); a.unmount(); // Reverse direction: child first, then parent rejected @@ -137,6 +143,7 @@ const nextMount = () => baseMountPoint + '-' + (mountCounter++); const d = vfs.create(); c.mount(child); assert.throws(() => d.mount(parent), { code: 'ERR_INVALID_STATE' }); + assertUnmounted(d, parent); c.unmount(); } @@ -147,6 +154,7 @@ const nextMount = () => baseMountPoint + '-' + (mountCounter++); const b = vfs.create(); a.mount(m); assert.throws(() => b.mount(m), { code: 'ERR_INVALID_STATE' }); + assertUnmounted(b, m); a.unmount(); }