Skip to content
Myr

Improve IPC error messages (#1090)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent 18e607c · Browse files · 5 files+42 added−29 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+42 added−29 removed

  • tests:+39 added−26 removed
  • other:+3 added−3 removed

5 files+42 added−29 removed

modified:lib/ipc/ipc-input.js+2 added-2 removed
modified:lib/ipc/validation.js+1 added-1 removed
modified:test/ipc/ipc-input.js+9 added-7 removed
modified:test/ipc/send.js+5 added-3 removed
60 unmodified lines
61 const subprocess = execa('ipc-get-send-get.js', ['false'], {ipc: true});62 await subprocess.sendMessage(foobarString);63 t.is(await subprocess.getOneMessage(), foobarString);6465 const {message} = await t.throwsAsync(subprocess.sendMessage(0n));66 t.true(message.includes('subprocess.sendMessage()\'s argument type is invalid'));65 const {message, cause} = await t.throwsAsync(subprocess.sendMessage(0n));66 t.is(message, 'subprocess.sendMessage()\'s argument type is invalid: the message cannot be serialized: 0.');67 t.true(cause.message.includes('The "message" argument must be one of type string'));6869 const {exitCode, isTerminated, stderr} = await t.throwsAsync(subprocess);70 t.is(exitCode, 1);71 t.false(isTerminated);
7 unmodified lines
7980 const {exitCode, isTerminated, stderr} = await t.throwsAsync(subprocess);81 t.is(exitCode, 1);82 t.false(isTerminated);82 t.true(stderr.includes('sendMessage()\'s argument type is invalid'));83 t.true(stderr.includes('Error: sendMessage()\'s argument type is invalid: the message cannot be serialized: 0.'));84 t.true(stderr.includes('The "message" argument must be one of type string'));85});8687// EPIPE happens based on timing conditions, so we must repeat it until it happens88const findEpipeError = async t => {
23 unmodified lines
modified:test/ipc/validation.js+25 added-16 removed
57 unmodified lines
58test('exports.sendMessage() after disconnection', testPostDisconnectionSubprocess, 'sendMessage');59test('exports.getOneMessage() after disconnection', testPostDisconnectionSubprocess, 'getOneMessage');60test('exports.getEachMessage() after disconnection', testPostDisconnectionSubprocess, 'getEachMessage');6162const INVALID_TYPE_MESSAGE = 'The "message" argument must be one of type string';63const UNDEFINED_MESSAGE = 'The "message" argument must be specified';64const CLONE_MESSAGE = 'could not be cloned';65const CYCLE_MESSAGE = 'Converting circular structure to JSON';66const MAX_CALL_STACK_MESSAGE = 'Maximum call stack size exceeded';6762const testInvalidPayload = async (t, serialization, message) => {68const testInvalidPayload = async (t, serialization, message, expectedMessage) => {69 const subprocess = execa('empty.js', {ipc: true, serialization});64 await t.throwsAsync(subprocess.sendMessage(message), {message: /type is invalid/});70 const error = await t.throwsAsync(subprocess.sendMessage(message));71 t.true(error.message.includes('subprocess.sendMessage()\'s argument type is invalid: the message cannot be serialized'));72 t.true(error.cause.message.includes(expectedMessage));73 await subprocess;74};7576const cycleObject = {};77cycleObject.self = cycleObject;78const toJsonCycle = {toJSON: () => ({test: true, toJsonCycle})};7972test('subprocess.sendMessage() cannot send undefined', testInvalidPayload, 'advanced', undefined);73test('subprocess.sendMessage() cannot send bigints', testInvalidPayload, 'advanced', 0n);74test('subprocess.sendMessage() cannot send symbols', testInvalidPayload, 'advanced', Symbol('test'));75test('subprocess.sendMessage() cannot send functions', testInvalidPayload, 'advanced', () => {});76test('subprocess.sendMessage() cannot send promises', testInvalidPayload, 'advanced', Promise.resolve());77test('subprocess.sendMessage() cannot send proxies', testInvalidPayload, 'advanced', new Proxy({}, {}));78test('subprocess.sendMessage() cannot send Intl', testInvalidPayload, 'advanced', new Intl.Collator());79test('subprocess.sendMessage() cannot send undefined, JSON', testInvalidPayload, 'json', undefined);80test('subprocess.sendMessage() cannot send bigints, JSON', testInvalidPayload, 'json', 0n);81test('subprocess.sendMessage() cannot send symbols, JSON', testInvalidPayload, 'json', Symbol('test'));82test('subprocess.sendMessage() cannot send functions, JSON', testInvalidPayload, 'json', () => {});83test('subprocess.sendMessage() cannot send cycles, JSON', testInvalidPayload, 'json', cycleObject);84test('subprocess.sendMessage() cannot send cycles in toJSON(), JSON', testInvalidPayload, 'json', toJsonCycle);80test('subprocess.sendMessage() cannot send undefined', testInvalidPayload, 'advanced', undefined, UNDEFINED_MESSAGE);81test('subprocess.sendMessage() cannot send bigints', testInvalidPayload, 'advanced', 0n, INVALID_TYPE_MESSAGE);82test('subprocess.sendMessage() cannot send symbols', testInvalidPayload, 'advanced', Symbol('test'), INVALID_TYPE_MESSAGE);83test('subprocess.sendMessage() cannot send functions', testInvalidPayload, 'advanced', () => {}, INVALID_TYPE_MESSAGE);84test('subprocess.sendMessage() cannot send promises', testInvalidPayload, 'advanced', Promise.resolve(), CLONE_MESSAGE);85test('subprocess.sendMessage() cannot send proxies', testInvalidPayload, 'advanced', new Proxy({}, {}), CLONE_MESSAGE);86test('subprocess.sendMessage() cannot send Intl', testInvalidPayload, 'advanced', new Intl.Collator(), CLONE_MESSAGE);87test('subprocess.sendMessage() cannot send undefined, JSON', testInvalidPayload, 'json', undefined, UNDEFINED_MESSAGE);88test('subprocess.sendMessage() cannot send bigints, JSON', testInvalidPayload, 'json', 0n, INVALID_TYPE_MESSAGE);89test('subprocess.sendMessage() cannot send symbols, JSON', testInvalidPayload, 'json', Symbol('test'), INVALID_TYPE_MESSAGE);90test('subprocess.sendMessage() cannot send functions, JSON', testInvalidPayload, 'json', () => {}, INVALID_TYPE_MESSAGE);91test('subprocess.sendMessage() cannot send cycles, JSON', testInvalidPayload, 'json', cycleObject, CYCLE_MESSAGE);92test('subprocess.sendMessage() cannot send cycles in toJSON(), JSON', testInvalidPayload, 'json', toJsonCycle, MAX_CALL_STACK_MESSAGE);9394test('exports.sendMessage() validates payload', async t => {95 const subprocess = execa('ipc-echo-item.js', {ipc: true});96 await subprocess.sendMessage([undefined]);97 const {message} = await t.throwsAsync(subprocess);90 t.true(message.includes('sendMessage()\'s argument type is invalid'));98 t.true(message.includes('Error: sendMessage()\'s argument type is invalid: the message cannot be serialized'));99 t.true(message.includes(UNDEFINED_MESSAGE));100});