Martin Aliger wrote:
Reasoning:
There are scenarios where you have to test, whether some element/attribute
is present in the xml. Its _not_ an error, if such element/attribute is
missing. Since xmlpeek task report it via exception, and even with
failonerror set it is considered error, blaming nant users with false
errors.
I'm open to any changes/expansions to this. Maybe defaultValue="whatever" is
better? (and use this value if no match found?)
As long as you're brainstorming options, another approach could be to
simply undefine the variable. (I'm not sure if that's even possible in
NAnt.)
In 90% of the cases, the user can first set the property to some
well-defined "null" value, run the task, and check the result. For
example, if you know the value you're fetching is supposed to be a
number, you could use the string "missing" as the default value, and use
a simple comparison to see whether or not the peek succeeded. The only
time this wouldn't work is if there are absolutely no constraints on the
possible data values, so that there's no way to pick a "null" value.
Since the defaultValue attribute has the same problem, I don't see any
advantage to it over simply setting the property to the default value in
advance, and my preference is avoid introducing attributes when there's
an easy alternative.
Finally, I'd really like to see the default behavior changed to not
cause a failure. The current behavior seems to violate the principle of
least surprise, at least to me. Besides, you can usually do a better
job with the error message, by simply detecting the failure and using
your own <fail> with wording more appropriate to the situation.
Gary
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
nant-developers mailing list
nant-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-developers