Reputation: 7317
Using the Error()
method only logs an error. But what if I want to abort the build? I can throw an exception to abort the build but it does not seem right. So is there a proper way to abort?
var releaseNotes = ParseReleaseNotes("./ReleaseNotes.md");
if(releaseNotes.Version.ToString() != nugetVersion)
{
Error("Release notes are missing an entry for v{0}. Latest release notes are for v{1}", nugetVersion, releaseNotes.Version);
throw new Exception();
}
Upvotes: 3
Views: 911
Reputation: 13844
The Error
method is just a convenience method for logging an error. I understand the confusion though.
If something is wrong with that you cannot recover from, you should throw an exception to indicate it. The Cake script runner will then log the error (using the Error
method) and return exit code 1 to indicate that something went wrong.
Upvotes: 3
Reputation: 7317
Ok, so the answer is to throw an exception and not use the Error()
method like this:
var releaseNotes = ParseReleaseNotes("./ReleaseNotes.md");
if(releaseNotes.Version.ToString() != nugetVersion)
{
throw new Exception("Release notes are missing an entry for v{0}. Latest release notes are for v{1}", nugetVersion, releaseNotes.Version);
}
Upvotes: 1