[Yanel-dev] exception handling in Ant tasks

Michael Wechner michael.wechner at wyona.com
Mon Apr 12 09:44:16 CEST 2010


Guillaume Déflache wrote:
> Michael Wechner schrieb:
>> Guillaume Déflache wrote:
>>> Could we stop logging exceptions in Ant tasks and simply rethrow 
>>> them as build exceptions (org.apache.tools.ant.BuildException).
>>> The Ant tasks's "execute" entry-point method that every task shall 
>>> implement already throws this type of exception so by only 
>>> (re)throwing it here and in other methods:
>>> - the stacktraces are simpler because they don't get displayed 
>>> and/or wrapped many times
>>> - one does not litter one's code with a lot of exception handling, 
>>> the only needed code is "throws BuildException" appended on all 
>>> methods signatures, or even "throws Exception" with only a exception 
>>> wrapper from Exception to BuildException on the "execute" method
>>> - errors ultimately get catched by Ant anyway, which already does a 
>>> great job at showing full stacktraces, *and failing the whole build*
>>>
>>>
>>> I am asking because I spent quite some time wondering why my 
>>> resource-type was not found, it was only because my project's 
>>> resource-types.xml was not well-formed and it just got ignored 
>>> because of these issues (culprit here being Yanel's 
>>> src/build/java/org/wyona/yanel/ant/MergeResourceTypesConfigsTask.java)... 
>>>
>>>
>>> Better fail fast than silently!!!
>>
>> I understand your frustration, but you need to be more specific by 
>> providing a patch of the MergeResourceTypesConfigsTask class
>
> Shall I do that now?
> The modification is pretty systematic as I tried to explain: remove 
> all "try { ...} catch" constructs and make all methods throws 
> Exception. Only the 'execute' method's contract will only allow 
> BuildException to be thrown so wrap Exception to BuildException there.

rather not, because I do not think we should "replace" *all* try/catch  
statements, but we really need to spend time on each case.

I will now implement the case of not well-formed resource-types.xml

>
>
>> re which errors you want to throw and give specific examples when 
>> these errors are thrown, e.g. resource-types.xml is not well-formed.
>
> I already gave an example:
> make your realm's resource-types.xml not well-formed => the build will 
> not break

it didn't sound like this was the only case/example



> Sadly you cannot provide an example log since AFAICS the errors do not 
> show up on the console, at least not at the log level I usually run 
> Ant (with ANT_ARGS=-q).

maybe you should consider running without -q

> Where are the log4j logs supposed to be written to in this case?

I think it's standard output/command line

> I am not sure which log4j properties file gets read here.

I am not sure either and would have to check


>
>> The case that your resource-types.xml is not found is NOT a build 
>> error, because a realm does not have to have such a file.
>
> It was a misformulation from my side, I should have written
> "spent quite some time wondering why my resource-type was not taken 
> into account" instead of "spent quite some time wondering why my 
> resource-type was not found".
> I am aware this file is not mandatory.

ok, maybe you want to add this to the documentation
>
>
>> That's rather a matter of documentation. Also you could enhance this 
>> documentation, e.g.
>>
>> http://www.yanel.org/en/documentation/configuration/resource-types_xml.html 
>>
>> http://www.yanel.org/en/documentation/create-new-resource.html
>
> We certainly could expand 
> http://www.yanel.org/en/documentation/configuration/resource-types_xml.html 
> with a rationale for the example and at 
> $YANELHOME/conf/local/local.resource-type.xml in the "Register New 
> Resource" section suggest to use $REALM_DIR/resource-types.xml instead 
> of $YANEL_HOME/conf/local/local.resource-types.xml
>
> Should I do that now?

yes, that would be great

Thanks

Michi



More information about the Yanel-development mailing list