Yossi Dahan [BizTalk]

Google
 

Monday, September 20, 2010

Flowing clear error messages from transforms

This one comes up every now and again, and although targeted at a specific group – those who use custom xsl for their transforms – as our very own Oleg Gershikov has a nice approach to it, it is worth repeating here -

You have an orchestration, in which you have a transform shape, and at runtime, the transform fails.
This usually results with a typical BizTalk error message – very detailed, and thus very useful – for those who can read it…
What you want is a clear, business related error message, how do you go about achieving that?

Well – to start with, you add some validation in your xsl script, and provide the relevant message, something along the lines of -

     <xsl:choose>
          <xsl:when test="$someVariable=''">
            <xsl:message terminate="yes">Here’s some nice error message, hopefully this will mean something to somebody….</xsl:message>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$someVariable"/>
          </xsl:otherwise>
        </xsl:choose>

Then, you make sure you have a scope around your transform shape, in which you catch the Microsoft.XLANGs.BaseTypes.TransformationFailureException exception

From that exception, you can extract the message provided by the script using -

if(xslex.InnerException != null)
{
   event.Message = event.Message + "Exception details: " + xslex.InnerException.Message;
}
else
{
   event.Message = event.Message + "Exception details: " + xslex.ToString();
}

and use that to change an error that previously looked something like -

Error encountered while executing the transform SomeTransform. Error:Transformation failed..Microsoft.XLANGs.Core.XTransformationFailureException: Error encountered while executing the transform SomeTransform. Error:Transformation failed.. ---> System.Xml.Xsl.XsltException: Transform terminated: '
              Here’s some nice error message, hopefully this will mean something to somebody….            '.
   at System.Xml.Xsl.XsltOld.MessageAction.Execute(Processor processor, ActionFrame frame)
   at System.Xml.Xsl.XsltOld.ActionFrame.Execute(Processor processor)
   at System.Xml.Xsl.XsltOld.Processor.Execute()
   at System.Xml.Xsl.XsltOld.Processor.Execute(Stream stream)
   at System.Xml.Xsl.XslTransform.Transform(XPathNavigator input, XsltArgumentList args, Stream output, XmlResolver resolver)
   at System.Xml.Xsl.XslTransform.Transform(IXPathNavigable input, XsltArgumentList args, Stream output, XmlResolver resolver)
   at Microsoft.XLANGs.Core.Service.ApplyTransform(Type mapRef, Object[] outParams, Object[] inParams)

To something like this -

The process failed. Transformation Exception occurred creating request.Exception details: Transform terminated: 
                Here’s some nice error message, hopefully this will mean something to somebody….  

0 Comments:

Post a Comment

<< Home