Skip to content

Commit 6f6dbc1

Browse files
committed
fix: normalize authorization stream creation errors
1 parent 9101e03 commit 6f6dbc1

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

scripts/zcode-companion.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ export function readInternalEnvelope(fd = 3, options = {}) {
257257
if (!Number.isSafeInteger(fd) || fd < 3 || !Number.isSafeInteger(maxBytes) || maxBytes <= 0 || !Number.isSafeInteger(timeoutMs) || timeoutMs <= 0) throw authorizationInputError();
258258
options.signal?.throwIfAborted();
259259
return new Promise((resolvePromise, reject) => {
260-
const stream = options.createStream?.(fd) ?? new Socket({ fd, readable: true, writable: false });
260+
let stream;
261+
try { stream = options.createStream?.(fd) ?? new Socket({ fd, readable: true, writable: false }); }
262+
catch { reject(authorizationInputError()); return; }
261263
let data = ''; let bytes = 0; let settled = false; let closed = false; let cleaned = false;
262264
/** @type {{resolve:true,value:any}|{resolve:false,value:unknown}|null} */
263265
let outcome = null;

tests/recovery.test.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,15 @@ test('internal envelope closes its owned stream once on success, error, and time
388388
}
389389
});
390390

391+
test('internal envelope maps synchronous stream construction failures to its stable error', async () => {
392+
await assert.rejects(
393+
readInternalEnvelope(33, { createStream: () => { throw new TypeError('secret unsupported descriptor'); } }),
394+
(error) => error instanceof PluginError
395+
&& error.code === 'INTERNAL_AUTHORIZATION_INVALID'
396+
&& !error.message.includes('secret'),
397+
);
398+
});
399+
391400
test('internal response writer times out without blocking the event loop and closes once', async () => {
392401
let closes = 0; let ticked = false; setImmediate(() => { ticked = true; });
393402
await assert.rejects(writeInternalResponse({ ok: true }, 44, { timeoutMs: 10, write: () => {}, close: (_fd, callback) => { closes += 1; callback(); } }), { code: 'INTERNAL_RESPONSE_WRITE_TIMEOUT' });

0 commit comments

Comments
 (0)