[Yanel-dev] exception handling in Ant tasks

Guillaume Déflache guillaume.deflache at wyona.com
Wed Apr 14 15:05:55 CEST 2010


Michael Wechner schrieb:
> 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

Another case I just stumbled upon is when the realm configuration file 
is not found:
> [merge-resource-types-configs] Realm context config: Realm context configuration:   ID = zwischengas,   Mount point = /,   Root flag = true,   Unresolved realm config file = /home/guillaume/zwischengas.VCWC/distribution/build/wyona_zwischengas_dist-r48758/zwischengas-realm_r48758/realm.xml
> [merge-resource-types-configs] 792  2010-04-14 14:56:11,903 [main] ERROR org.wyona.yanel.ant.MergeResourceTypesConfigsTask.mergeResourceTypesOfRealm():?  - Neither file nor directory: /home/guillaume/zwischengas.VCWC/distribution/build/wyona_zwischengas_dist-r48758/zwischengas-realm_r48758/realm.xml
> 
> init:
[Ant continues to build after that.]


>> 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

You were right, see above.


>> I am not sure which log4j properties file gets read here.
> 
> I am not sure either and would have to check
[...]


More information about the Yanel-development mailing list