mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-07 07:27:06 -04:00
fix: don't crash if completion function fails
This commit is contained in:
@@ -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') {
|
||||
|
||||
@@ -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: {},
|
||||
|
||||
Reference in New Issue
Block a user