Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix($markdown): notify error when not found snippet #1872 #1910

Merged
merged 2 commits into from
Oct 11, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/@vuepress/markdown/lib/snippet.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { fs, path } = require('@vuepress/shared-utils')
const { fs, logger, path } = require('@vuepress/shared-utils')

module.exports = function snippet (md, options = {}) {
const fence = md.renderer.rules.fence
Expand All @@ -15,8 +15,10 @@ module.exports = function snippet (md, options = {}) {
if (fs.existsSync(src)) {
token.content = fs.readFileSync(src, 'utf8')
} else {
token.content = 'Not found: ' + src
const errorMessage = `Not found: ${src}`
token.content = errorMessage
token.info = ''
logger.error(errorMessage)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think temp variable is really useful here. Error log message can also be improved (now that it's also log in the server console)

Here is a suggestion

token.content = `Code snippet path not found: ${src}`
token.info = ''
logger.error(token.content)

}
}
return fence(...args)
Expand Down