feat: show path that caused the error

This commit is contained in:
MDLeom 2020-09-05 11:58:20 +00:00
parent c57e227efd
commit 51cc9b1d8d
No known key found for this signature in database
GPG Key ID: 06C236E63CBC68AA
7 changed files with 20 additions and 20 deletions

View File

@ -76,7 +76,7 @@ function minifyHtml (str, data) {
return result
} catch (err) {
throw new Error(err)
throw new Error(`Path: ${path}\n${err}`)
}
}
@ -95,7 +95,7 @@ async function minifyCss (str, data) {
if (verbose) logFn.call(this, str, styles, path, 'css')
return styles
} catch (err) {
throw new Error(err)
throw new Error(`Path: ${path}\n${err}`)
}
}
@ -124,7 +124,7 @@ async function minifyJs (str, data) {
if (verbose) logFn.call(this, str, code, path, 'js')
return code
} catch (err) {
throw new Error(err)
throw new Error(`Path: ${path}\n${err}`)
}
}
@ -149,7 +149,7 @@ function minifySvg () {
if (verbose) logFn.call(this, assetTxt, data, path, 'svg')
resolve(route.set(path, data))
} catch (err) {
reject(new Error(err))
reject(new Error(`Path: ${path}\n${err}`))
}
}
resolve()
@ -181,7 +181,7 @@ function gzipFn () {
if (verbose) logFn.call(this, assetTxt, result, path, 'gzip')
resolve(route.set(path + '.gz', result))
} catch (err) {
reject(new Error(err))
reject(new Error(`Path: ${path}\n${err}`))
}
}
resolve()
@ -213,7 +213,7 @@ function brotliFn () {
if (verbose) logFn.call(this, assetTxt, result, path, 'brotli')
resolve(route.set(path + '.br', result))
} catch (err) {
reject(new Error(err))
reject(new Error(`Path: ${path}\n${err}`))
}
}
resolve()
@ -243,7 +243,7 @@ function minifyXml () {
if (verbose) logFn.call(this, assetTxt, result, path, 'xml')
resolve(route.set(path, result))
} catch (err) {
reject(new Error(err))
reject(new Error(`Path: ${path}\n${err}`))
}
}
resolve()
@ -273,7 +273,7 @@ function minifyJson () {
if (verbose) logFn.call(this, assetTxt, result, path, 'json')
resolve(route.set(path, result))
} catch (err) {
reject(new Error(err))
reject(new Error(`Path: ${path}\n${err}`))
}
}
resolve()

View File

@ -76,11 +76,11 @@ describe('css', () => {
try {
await new CleanCSS(customOpt).minify(input)
} catch (err) {
expected = err.message
expected = err
}
expect(expected).toBeDefined()
await expect(c(input, { path })).rejects.toThrow(expected)
await expect(c(input, { path })).rejects.toThrow(`Path: ${path}\n${expected}`)
})
test('exclude - *.min.css', async () => {

View File

@ -103,10 +103,10 @@ describe('gzip', () => {
try {
await gzip(input, customOpt)
} catch (err) {
expected = err.message
expected = err
}
expect(expected).toBeDefined()
await expect(g()).rejects.toThrow(expected)
await expect(g()).rejects.toThrow(`Path: ${path}\n${expected}`)
})
test('include - exclude non-text file by default', async () => {

View File

@ -125,6 +125,6 @@ describe('html', () => {
expect(() => {
h(invalid, { path })
}).toThrow('Parse Error')
}).toThrow(`Path: ${path}\nError: Parse Error`)
})
})

View File

@ -82,15 +82,15 @@ describe('js', () => {
}
hexo.config.minify.js = customOpt
let error
let expected
try {
await terserMinify(input, customOpt)
} catch (err) {
error = err.message
expected = err
}
expect(error).toBeDefined()
await expect(j(input, { path })).rejects.toThrow(error)
expect(expected).toBeDefined()
await expect(j(input, { path })).rejects.toThrow(`Path: ${path}\n${expected}`)
})
test('exclude - *.min.js', async () => {
@ -118,6 +118,6 @@ describe('js', () => {
test('invalid string', async () => {
const invalid = 'console.log("\\");'
await expect(j(invalid, { path })).rejects.toThrow('SyntaxError')
await expect(j(invalid, { path })).rejects.toThrow(`Path: ${path}\nSyntaxError`)
})
})

View File

@ -57,7 +57,7 @@ describe('xml', () => {
test('invalid input', async () => {
hexo.route.set(path, 'foo')
await expect(jsonFn()).rejects.toThrow(/SyntaxError/)
await expect(jsonFn()).rejects.toThrow(`Path: ${path}\nSyntaxError`)
})
test('empty file', async () => {

View File

@ -89,7 +89,7 @@ describe('svg', () => {
expected = err
}
expect(expected).toBeDefined()
await expect(s()).rejects.toThrow(expected)
await expect(s()).rejects.toThrow(`Path: ${path}\n${expected}`)
})
test('include - exclude *.min.svg by default', async () => {