node/test/parallel/test-fs-filehandle.js
Anna Henningsen 2703db7985
src: show original file name in FileHandle GC close errors
Otherwise, it can be virtually impossible to debug where these types
of errors originate from.

PR-URL: https://github.com/nodejs/node/pull/60593
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2025-11-07 15:57:05 +00:00

31 lines
950 B
JavaScript

// Flags: --expose-gc --no-warnings --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
const { internalBinding } = require('internal/test/binding');
const fs = internalBinding('fs');
const { stringToFlags } = require('internal/fs/utils');
const filepath = path.toNamespacedPath(__filename);
// Verifies that the FileHandle object is garbage collected and that an
// error is thrown if it is not closed.
process.on('uncaughtException', common.mustCall((err) => {
assert.strictEqual(err.code, 'ERR_INVALID_STATE');
assert.match(err.message, /^A FileHandle object was closed during/);
assert.match(err.message, new RegExp(RegExp.escape(filepath)));
}));
{
const ctx = {};
fs.openFileHandle(filepath,
stringToFlags('r'), 0o666, undefined, ctx);
assert.strictEqual(ctx.errno, undefined);
}
globalThis.gc();
setTimeout(() => {}, 10);