Skip to content

Commit 47e933d

Browse files
authored
fix: group failed scripts log (#254)
1 parent 69e6d8f commit 47e933d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/assets.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export function setupPublicAssetStrategy(options: ModuleOptions['assets'] = {})
9494
await fsp.rm(cacheDir, { recursive: true, force: true })
9595
await fsp.mkdir(cacheDir, { recursive: true })
9696
let banner = false
97+
const failedScriptDownload = new Set<{ url: string, statusText: string, status: number }>()
9798
for (const [filename, url] of renderedScriptSrc) {
9899
const key = `data:scripts:${filename}`
99100
// Use storage to cache the font data between builds
@@ -107,7 +108,8 @@ export function setupPublicAssetStrategy(options: ModuleOptions['assets'] = {})
107108
let size = 0
108109
res = await fetch(url).then((r) => {
109110
if (!r.ok) {
110-
throw new Error(`@nuxt/scripts - Failed to download script: ${url}. ${r.statusText} (${r.status})`)
111+
failedScriptDownload.add({ url, statusText: r.statusText, status: r.status })
112+
return Buffer.from('')
111113
}
112114
encoding = r.headers.get('content-encoding')
113115
const contentLength = r.headers.get('content-length')
@@ -119,6 +121,9 @@ export function setupPublicAssetStrategy(options: ModuleOptions['assets'] = {})
119121
}
120122
await fsp.writeFile(join(cacheDir, filename), res)
121123
}
124+
if (failedScriptDownload.size) {
125+
throw new Error(`@nuxt/script: Failed to download scripts:\n${[...failedScriptDownload].map(({ url, statusText, status }) => ` ├─ ${url} (${status} ${statusText})`).join('\n')}`)
126+
}
122127
if (banner)
123128
logger.success('Scripts downloaded and cached.')
124129
})

0 commit comments

Comments
 (0)