[Yanel-dev] exception handling in Ant tasks
Guillaume Déflache
guillaume.deflache at wyona.com
Mon Apr 12 10:29:17 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
OK.
>>> 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
Really it was sound-distortion by frustration! ;)
I had other problems because I thought the resource-types.xml has to be
placed directly under the realm directory (where build.xml is located)
whereas it has to be in the same directory as the realm configuration
file (e.g. realm.xml).
>> 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
Indeed, maybe not using -q would have revealed this.
>> 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
I will.
>>> 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
OK, doing that now.
I'll add another simpler example for project-specific resource-types.xml
files (taken from the from-scratch realm) as the existing one is rather
lengthy.
BTW I noticed that for project-specific resource-types.xml files on
'resource-type' elements:
- AFAICS the 'src' attributes do not have to end with "/" to work
- the paths for these attributes are also really relative to the
directory where the realm configuration file (e.g. realm.xml) is, not to
the realm directory (where build.xml is)
I will document the second point, but I won't document the first as I am
not so sure it works in all cases (with 'copy-dir-name' attribute for
example) so I will only experiment that on my current project and see if
it goes well.
More information about the Yanel-development
mailing list