diff --git a/packages/pnpm/src/cmd/complete.ts b/packages/pnpm/src/cmd/complete.ts index c468ea9142..7f1c54f3be 100644 --- a/packages/pnpm/src/cmd/complete.ts +++ b/packages/pnpm/src/cmd/complete.ts @@ -52,7 +52,11 @@ export default async function complete ( if (!input.cmd || input.currentTypedWordType === 'value' && !ctx.completionByCommandName[input.cmd]) { completions = ctx.initialCompletion() } else if (ctx.completionByCommandName[input.cmd]) { - completions = await ctx.completionByCommandName[input.cmd](input.args, input.options) + try { + completions = await ctx.completionByCommandName[input.cmd](input.args, input.options) + } catch (err) { + // Ignore + } } } if (input.currentTypedWordType === 'value') { diff --git a/packages/pnpm/test/complete.test.ts b/packages/pnpm/test/complete.test.ts index 25ecb133d6..aed7f843b8 100644 --- a/packages/pnpm/test/complete.test.ts +++ b/packages/pnpm/test/complete.test.ts @@ -91,6 +91,32 @@ test('complete a command', async (t) => { t.end() }) +test('if command completion fails, return empty array', async (t) => { + t.deepEqual( + await complete( + { + cliOptionsTypesByCommandName: {}, + completionByCommandName: { + run: async () => { throw new Error('error') }, + }, + globalOptionTypes: { + filter: String, + }, + initialCompletion: () => [], + }, + { + args: [], + cmd: 'run', + currentTypedWordType: 'value', + lastOption: null, + options: {}, + }, + ), + [], + ) + t.end() +}) + test('initial completion', async (t) => { const ctx = { cliOptionsTypesByCommandName: {},