Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stopping Tridion publishing with exceptions

Tags:

tridion

I would like to stop publishing when a certain condition exists in Tridion 2011. In a Razor template I try:

throw new Exception("Exceptional condition!");

But, in Template Builder it says 'successful'.

Any ideas?

In VBScript templates we would do Err.Raise and it would throw the error back to the Publish Queue.

like image 229
robrtc Avatar asked Dec 14 '12 10:12

robrtc


2 Answers

There's definitely not any try/catch mechanisms in the base Razor Mediator code, an error in the template should surface (as you see with the common null reference errors you probably run into a lot while razoring it up!). There's some things you should definitely check:

  1. Is the code path with the exception even being executed? As Bart suggested, you should run it through Template Builder and see if there are any useful logs there. Throw in your own debug statements as well to locate where the code path is going.

  2. Is your Exception in a correctly formatted razor statement?

  3. If its a new CT, does the Page Template's code allow the rendering of your CT?

I just setup a sample TBB as follows (and added TBB to a Component Template):

<div>Testing an Error</div>
@{ throw new Exception("Exceptional condition"); }

Running through Template Builder showed the error in the Output window. Previewing the page with a component using the CT would fail and show the error. Publishing the page showed "Failed" as status, with the Processed Items detailing showing the "Exceptional condition!" message.

Hope that helps, if you are still having trouble with it feel free to post your code and I'll debug it further!

like image 133
Alex Klock Avatar answered Oct 14 '22 12:10

Alex Klock


Sounds to me like the Razor Mediator is catching your exception and not re-throwing it. But a quick look at the code didn't give me a direct indication of where that would happen.

There are quite a few try, catch blocks in there (some are probably correct and expected), most are logging warnings.

Do you get anything interesting in the template builder log? If not I would try loading the Razor Mediator code and debug it while you run your Template, to see what catches your exception and if you can easily change that (good thing it's open source).

like image 30
Bart Koopman Avatar answered Oct 14 '22 12:10

Bart Koopman