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

handling errors properly #62

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

AndyOGo
Copy link

@AndyOGo AndyOGo commented Feb 15, 2017

fixes #61

if (!/\.(pug|jade)/.test(path.extname(file))) {
return
}
try {
Copy link
Owner

Choose a reason for hiding this comment

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

only wrap the actual pug calls, not the whole logic block.

Copy link
Author

@AndyOGo AndyOGo Feb 16, 2017

Choose a reason for hiding this comment

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

Yeah that was my initial approach too.
Buuut, the nice thing about throw is that it "breaks" forEach like break does with a classic loop.
Hence I decided to wrap the whole block.
Otherwise we would need to accumulate errors in an array...

Copy link
Author

Choose a reason for hiding this comment

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

Well, I prefer to bail-out on first error, but I can quickly change it to try all files.

files[name] = data
})

setImmediate(done)
Copy link
Owner

Choose a reason for hiding this comment

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

can just call done() instead of using setImmediate given the new direction

Copy link
Author

Choose a reason for hiding this comment

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

nope, setImmediate let's other i/o operations taking place before calling the next metalsmith plugin. see: https://nodejs.org/api/timers.html#timers_setimmediate_callback_args

@ahmadnassri
Copy link
Owner

need to add a test as well.

@AndyOGo
Copy link
Author

AndyOGo commented Feb 15, 2017

here you go, a simple test to check if err is truthy

@AndyOGo
Copy link
Author

AndyOGo commented Feb 17, 2017

@ahmadnassri
Are you happy with this PR?
If you insist on your suggestions, I really recommend not to do it for the above reasons.
Otherwise it's your baby, so I could still change it. For me it is very important to get this out asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Errors are not passed to metalsmith's done callback
2 participants