sayedihashimi / slow-cheetah

XML Transforms for app.config and other XML files
Other
242 stars 54 forks source link

TransformXml.Execute may hide root cause XmlException #45

Closed chriseldredge closed 7 years ago

chriseldredge commented 11 years ago

Using SlowCheetah.Tasks 1.0.10727.0, if an XmlException is thrown in TransformXml.Execute, the catch block will try to parse a URI from the exception instance's Source property. When that property is blank, a UriFormatException is thrown.

This bug causes an unhandled exception to be thrown by the task and the finally block incorrectly reports "Transformation succeeded".

sayedihashimi commented 11 years ago

Hi @chriseldredge could you give more specific steps to repro this?

chriseldredge commented 11 years ago

Add this line to appSettings in App.config:

<add key="example" value="&lt;hello>" />

The problem is the unescaped greater-than in the value, but the root cause exception is hidden by a UriFormatException.

sayedihashimi commented 11 years ago

OK thanks, this is a bug in XDT so it may take a bit longer to get this fixed.

chriseldredge commented 11 years ago

I agree the underlying issue may be in XDT, but the exception handling code should check to see if XmlException.Source is non-null/non-blank before attempting to parse it to avoid masking the underlying issue, whatever it may be.

sayedihashimi commented 11 years ago

@chriseldredge what exception handling code are you referring to? Is it in SlowCheetah or XDT?

chriseldredge commented 11 years ago

According to the stacktrace, the problem is probably in a catch block in TransformXml.Execute:

System.UriFormatException: Invalid URI: The URI is empty.
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
   at System.Uri..ctor(String uriString)
   at SlowCheetah.Tasks.TransformXml.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext()
sayedihashimi commented 11 years ago

@chriseldredge that task is a straight port of XDT. We are releasing XDT with the necessary license for SlowCheetah to redistribute it. See http://nuget.codeplex.com/discussions/405195. Once I do that I will get rid of SlowCheetah.Tasks all together.

I'll keep this open for now so that I do not forget about this but I'll have to look into fixing this after the switch and then try and get it fixed in the XDT version.

sayedihashimi commented 11 years ago

Now that I've switched over to the official XDT this may be resolved. We will look before the next release.

davilimap commented 7 years ago

With the newest version of XDT (as well as SlowCheetah), this is fixed.