Skip to content

Commit 3b754ab

Browse files
committed
Improve debug & error message clarity
1 parent 76a1349 commit 3b754ab

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ function permalinks(options) {
250250

251251
return function permalinks(files, metalsmith, done) {
252252
const debug = metalsmith.debug('@metalsmith/permalinks')
253-
debug.info('Running with options: %O', normalizedOptions)
253+
debug.info('Running with options (normalized): %O', normalizedOptions)
254254

255255
if (normalizedOptions.relative || normalizedOptions.linksets.find((ls) => ls && ls.relative)) {
256256
return done(new Error('The "relative" option is no longer supported.'))
@@ -265,13 +265,11 @@ function permalinks(options) {
265265
.forEach((file) => {
266266
const data = files[file]
267267
const hasOwnPermalinkDeclaration = !!data.permalink
268-
debug('checking file: %s', file)
269-
270268
const linkset = findLinkset(data, file, metalsmith)
271269
const permalinkTransformContext = { ...normalizedOptions, ...defaultLinkset, ...linkset }
272270
if (hasOwnPermalinkDeclaration) permalinkTransformContext.pattern = data.permalink
273271

274-
debug('applying pattern: %s to file: %s', linkset.pattern, file)
272+
debug('Applying pattern: "%s" to file: "%s"', linkset.pattern, file)
275273

276274
let ppath
277275

@@ -292,7 +290,7 @@ function permalinks(options) {
292290

293291
// invalid on Windows, but best practice not to use them anyway
294292
if (new RegExp(invalidPathChars).test(ppath)) {
295-
const msg = `Filepath "${file}" contains invalid filepath characters (one of :|<>"*?) after resolving as linkset pattern "${linkset.pattern}"`
293+
const msg = `Permalink "${ppath}" for file "${file}" contains invalid filepath characters (one of :|<>"*?) after resolution with linkset pattern "${linkset.pattern}"`
296294
debug.error(msg)
297295
return done(new Error(msg))
298296
}
@@ -315,6 +313,8 @@ function permalinks(options) {
315313

316314
delete files[file]
317315
files[out] = data
316+
317+
debug('Moved file "%s" to "%s" (permalink = "%s")', file, out, data.permalink)
318318
})
319319

320320
done()

test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ describe('@metalsmith/permalinks', () => {
290290
try {
291291
assert.strictEqual(
292292
err.message,
293-
'Filepath "post.html" contains invalid filepath characters (one of :|<>"*?) after resolving as linkset pattern ":title"'
293+
'Permalink ":title" for file "post.html" contains invalid filepath characters (one of :|<>"*?) after resolution with linkset pattern ":title"'
294294
)
295295
done()
296296
} catch (err) {

0 commit comments

Comments
 (0)