Skip to content

Commit

Permalink
feat: show path that caused the error
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Sep 5, 2020
1 parent c57e227 commit 51cc9b1
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
16 changes: 8 additions & 8 deletions lib/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function minifyHtml (str, data) {

return result
} catch (err) {
throw new Error(err)
throw new Error(`Path: ${path}\n${err}`)
}
}

Expand All @@ -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}`)
}
}

Expand Down Expand Up @@ -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}`)
}
}

Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions test/css.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions test/gzip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/html.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ describe('html', () => {

expect(() => {
h(invalid, { path })
}).toThrow('Parse Error')
}).toThrow(`Path: ${path}\nError: Parse Error`)
})
})
10 changes: 5 additions & 5 deletions test/js.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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`)
})
})
2 changes: 1 addition & 1 deletion test/json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/svg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 51cc9b1

Please sign in to comment.