Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit af5c8f7

Browse filesBrowse files
committed
Handle Coana npm fallback spawn errors
1 parent 1549f69 commit af5c8f7
Copy full SHA for af5c8f7

2 files changed

+46-7Lines changed: 46 additions & 7 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/utils/dlx.mts‎

Copy file name to clipboardExpand all lines: src/utils/dlx.mts
+11-7Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,17 @@ async function spawnCoanaViaNpmInstall(
316316
message: `npm install fallback failed: ${stderr || cause}`,
317317
}
318318
}
319-
return await spawnCoanaScriptViaNode(
320-
scriptPath,
321-
args,
322-
finalEnv,
323-
options,
324-
spawnExtra,
325-
)
319+
try {
320+
return await spawnCoanaScriptViaNode(
321+
scriptPath,
322+
args,
323+
finalEnv,
324+
options,
325+
spawnExtra,
326+
)
327+
} catch (e) {
328+
return buildDlxErrorResult(e)
329+
}
326330
}
327331

328332
/**
Collapse file

‎src/utils/dlx.test.mts‎

Copy file name to clipboardExpand all lines: src/utils/dlx.test.mts
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,5 +388,40 @@ describe('utils/dlx', () => {
388388
expect(result.message).toContain('npm-install fallback also failed')
389389
expect(result.message).toContain('registry unreachable')
390390
})
391+
392+
it('surfaces both dlx and node errors when fallback node spawn fails', async () => {
393+
mockSpawn.mockImplementation(async (cmd: string, args: string[]) => {
394+
if (cmd === 'npm' && args[0] === 'install') {
395+
const prefixIdx = args.indexOf('--prefix')
396+
const installDir = args[prefixIdx + 1]
397+
const pkgDir = path.join(
398+
installDir,
399+
'node_modules',
400+
'@coana-tech',
401+
'cli',
402+
)
403+
await fs.mkdir(pkgDir, { recursive: true })
404+
await fs.writeFile(
405+
path.join(pkgDir, 'package.json'),
406+
JSON.stringify({ bin: { coana: 'dist/cli.js' } }),
407+
)
408+
return { stdout: '', stderr: '' }
409+
}
410+
throw Object.assign(new Error('node boom'), {
411+
code: 127,
412+
stderr: 'node failed',
413+
})
414+
})
415+
416+
const result = await spawnCoanaDlx(['run', '.'], 'acme', {
417+
coanaVersion: nextVersion(),
418+
})
419+
420+
expect(result.ok).toBe(false)
421+
expect(result.message).toContain('Coana command failed')
422+
expect(result.message).toContain('npx aborted')
423+
expect(result.message).toContain('npm-install fallback also failed')
424+
expect(result.message).toContain('node failed')
425+
})
391426
})
392427
})

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.