Skip to content

Commit e652f03

Browse files
authored
wpt: properly handle write permissions errors in wpt-runner setup (#4518)
1 parent 0395679 commit e652f03

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

test/web-platform-tests/wpt-runner.mjs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,18 +407,28 @@ async function setup () {
407407
`The WPT require certain entries to be present in your ${hostsPath} file. Should these be configured automatically? (y/n): `,
408408
resolve
409409
)
410-
}).finally(() => rl.close())
410+
}).finally(() => rl.close()).then((a) => a.trim().toLowerCase())
411411

412-
if (answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes') {
413-
await setupHostsFile()
414-
} else {
412+
let hostsModified = false
413+
if (answer === 'y' || answer === 'yes') {
414+
try {
415+
await setupHostsFile()
416+
hostsModified = true
417+
} catch (err) {
418+
console.error('❌ \x1B[31mAutomatic configuration failed.\x1B[0m')
419+
}
420+
}
421+
if (!hostsModified) {
415422
console.log('Please configure hosts file manually:')
416423
console.log(`cd ${WPT_DIR}`)
417424
if (process.platform === 'win32') {
418425
console.log('python wpt make-hosts-file | Out-File $env:SystemRoot\\System32\\drivers\\etc\\hosts -Encoding ascii -Append')
419426
} else {
420427
console.log('python3 wpt make-hosts-file | sudo tee -a /etc/hosts')
421428
}
429+
430+
console.log('❌ \x1B[31mSetup incomplete.\x1B[0m')
431+
process.exit(1)
422432
}
423433
}
424434

0 commit comments

Comments
 (0)