John W. Long wrote:
> Jay Levitt wrote:
>> Jay Levitt wrote:
>>> I understand the intent, but I wonder if there's a less intrusive way to 
>>> accomplish it, while still allowing outer tags to rescue their own 
>>> exceptions.  What if that rescue were executed only on the outermost 
>>> tags?  Would that break anything?  
>> I've submitted a patch that accomplishes this - ticket #177.
> 
> This sounds like a useful idea. Can you post some code which 
> demonstrates why this would be useful? Also I'll need unit tests before 
> this can be applied to the core.

I've been thinking over how to unit test it - more so since I found two 
bugs in it (one fixed in the second patch, one not yet fixed).  The 
problem, of course, is that disabling exceptions in "test" makes it 
impossible to test the code path that would trap the exception!

I'm thinking the best way is to add a global like 
RERAISE_EXCEPTIONS_IN_TEST, which the test itself would turn off and 
would otherwise default on.  Sound ok?

As for code that makes use of it, here:

   tag "outer" do |tag|
     contents = tag.expand
     html = "<header>" + do_something(contents) + "<footer>"
   end

   tag "inner" do |tag|
     ['height', 'font_size'].each do |attr|
       unless tag.attr.include?(attr)
         raise TagError, "the #{name} tag must include a '#{attr}' 
attribute."
       end
     end
   end

With Radiant 0.5, the error returned by "inner" gets trapped by the 
first render_tag it sees, and so the output is "<header>the inner tag 
must include a 'height' attribute<footer>", which (in my case) isn't the 
desired result; outer depends on inner, and I want everything or nothing.

With the patch, render_tag doesn't rescue the exception when rendering 
inner, so it goes up the stack.  In this particular case, "outer" 
doesn't catch it either, so the render_tag for outer rescues it and 
displays the error message in lieu of the outer tag.

If, in fact, I wanted to render outer no matter what, then I'd make 
"outer" something like

   tag "outer" do |tag|
     begin
       contents = tag.expand
     rescue TagError => e
       LOGGER.debug ("Inner error: #{e.message})
     ensure
       html = "<header>" + do_something(contents) + "<footer>"
     end
   end

Jay

_______________________________________________
Radiant mailing list
[email protected]
http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to