gruntjs/grunt — pull request #605 by sorccu (2013-01-06 10:12:50+00:00)
Title: Remove side effects from manually requiring grunt.

Previously [PR536](https://github.com/gruntjs/grunt/pull/536), now applied to latest master:

I had the need to do a `require('grunt')` in my own app. However just doing so would cause all uncaught exceptions in my own app to be caught by grunt, which would then print out the error message but leave out everything useful like the stack trace. In my case I actually had to require grunt during a test run (the app is a bit special, bear with me) so it was dying on every async assertion. In short, this behavior makes building certain types of apps around grunt very difficult.

Furthermore and in general, I believe you also agree that just requiring something should not alter your environment.

So, I made some minor changes: the uncaughtException handler is moved to right before the task run starts, and removed after finishing in the done callback. The error callback calls `fail.warn` which either exists directly or just keeps going, so I didn't add it there.

Seeing how the code is commented out in 0.3.17, I don't think this patch introduces any breaking changes.

__Note: No change in test results, but the current master (and therefore this branch) have an unrelated failure in the `subgrunt:all` task, so if Travis is not happy that's why.__