<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Okay, I managed to rig up something that appears to work. All this
goes in the main class. The intent is to call <tt>validate_components
</tt>once, and use any error it generates as a value for
$c->error() in all future requests. Any feedback or comments
welcome. It could be a little cleaner, but any indication about
whether the logic is sound would be very welcome.<br>
<br>
<tt>my $validated = 0;<br>
my $validation_error;<br>
<br>
sub validate_components {<br>
my ($c) = @_;<br>
return if ($validated);<br>
$validated = 1;<br>
<br>
# Now do the validation. Code that follows should croak if
something is wrong.<br>
...<br>
}<br>
<br>
around dispatch => sub {<br>
my ($orig, $c) = @_;<br>
my $result;<br>
my $error;<br>
my $eval_result;<br>
<br>
if (! $validation_error) {<br>
$eval_result = eval {<br>
$c->validate_components();<br>
};<br>
$error = $@;<br>
if ($eval_result || ! $error) {<br>
$result = $c->$orig(@_);<br>
}<br>
}<br>
<br>
if ($validation_error || (! $eval_result && $error)) {<br>
$c->error($validation_error //= $error);<br>
}<br>
return $result;<br>
};</tt><br>
<br>
<br>
<div class="moz-signature"><span style="color: rgb(102, 0, 0);">Stuart
Watt<br>
ARM Product Developer<br>
Information Balance</span></div>
<br>
On 8/31/2010 10:50 AM, Stuart Watt wrote:
<blockquote cite="mid:4C7D16B9.9040006@infobal.com" type="cite">
Looks like I was wrong in where the error occurred, although the
main issue is unchanged. The problem is in finalize rather than
prepare. <br>
<br>
On 8/31/2010 10:08 AM, Bill Moseley wrote:
<blockquote
cite="mid:AANLkTik8dte1JpXeKbYBaVhrNPyu7YE0ja2HPRyZC80B@mail.gmail.com"
type="cite">Even the top-level handle_request is wrapped in an
eval, but it tests $@ instead of the return value of eval like
it should. Is it possible something is clearing the $@ var?
<div class="gmail_quote">
<div><br>
</div>
<div>It's pretty easy to edit Catalyst.pm to check.</div>
<div><br>
</div>
</div>
</blockquote>
I hadn't seen the eval return value issue, although you're right.
The error is reported on the console just fine. The problem is,
that is the *only* place it is reported. The eval wrapper causes
the finalize to be partially skipped.<br>
<br>
Here's the stack trace at point of failure (more or less):<br>
<br>
$ =
ARM::Model::User::get_session_store_delegate(ref(ARM::Model::User),
'fbc69cb40a085cae169b26034f64832d12a9c305') called from file
`C:/perl/site/5.10.1/lib/Catalyst/Plugin/Session/Store/Delegate.pm'
line 56<br>
$ =
Catalyst::Plugin::Session::Store::Delegate::get_session_store_delegate(ref(ARM),
'fbc69cb40a085cae169b26034f64832d12a9c305') called from file
`C:/perl/site/5.10.1/lib/Catalyst/Plugin/Session/Store/Delegate.pm'
line 40<br>
$ =
Catalyst::Plugin::Session::Store::Delegate::session_store_delegate(ref(ARM))
called from file
`C:/perl/site/5.10.1/lib/Catalyst/Plugin/Session/Store/Delegate.pm'
line 94<br>
. =
Catalyst::Plugin::Session::Store::Delegate::store_session_data(ref(ARM),
'expires:fbc69cb40a085cae169b26034f64832d12a9c305', 1283271921)
called from file
`C:/perl/site/5.10.1/lib/Catalyst/Plugin/Session.pm' line 148<br>
. = Catalyst::Plugin::Session::_save_session_expires(ref(ARM))
called from file
`C:/perl/site/5.10.1/lib/Catalyst/Plugin/Session.pm' line 106<br>
. = Catalyst::Plugin::Session::finalize_headers(ref(ARM)) called
from file `C:/perl/site/5.10.1/lib/Catalyst.pm' line 1762<br>
$ = Catalyst::finalize(ref(ARM)) called from file
`C:/perl/site/5.10.1/lib/Catalyst/Plugin/Compress/Deflate.pm' line
16<br>
[other plugins here]<br>
$ = Catalyst::Plugin::Session::PerUser::finalize(ref(ARM)) called
from file
`C:/perl/site/5.10.1/lib/MSWin32-x86-perlio/Class/MOP/Method/Wrapped.pm'
line 48<br>
...<br>
$ = ARM::finalize(ref(ARM)) called from file
`C:/perl/site/5.10.1/lib/Catalyst.pm' line 1927<br>
<br>
So, the issue is: because I use
Catalyst::Plugin::Session::Store::Delegate, my model methods are
called in the finalize. These methods (based on my DBIC model
class) die, and this drops all feedback, as finalize_headers is
never completed and finalize_body never called. So I could
overcome this by fixing my model to never fail - proxying off the
DBIC class in some way to fake session handling on error.
(Although I suspect this might be better part of
Catalyst::Plugin::Session::Store::Delegate.)<br>
<br>
The problem is: finalize_headers is normally called after
finalize_error, so even if I detect an error, there seems to be no
way to go back and display that error. It seems to me that my
model code ought to be able to fail in a reasonable way and get
something displayed. <br>
<br>
--S<br>
<br>
<div class="moz-signature"><span style="color: rgb(102, 0, 0);">Stuart
Watt<br>
ARM Product Developer<br>
Information Balance</span></div>
<br>
<br>
<br>
<blockquote
cite="mid:AANLkTik8dte1JpXeKbYBaVhrNPyu7YE0ja2HPRyZC80B@mail.gmail.com"
type="cite">-- <br>
Bill Moseley<br>
<a moz-do-not-send="true" href="mailto:moseley@hank.org">moseley@hank.org</a><br>
<br>
-- <br>
This message was scanned by ESVA and is believed to be clean. <br>
<a moz-do-not-send="true"
href="http://antispam.infobal.com/cgi-bin/learn-msg.cgi?id=BAC6E2807E.050DF">Click
here to report this message as spam.</a>
<pre wrap=""><fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
List: <a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a>
Listinfo: <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst</a>
Searchable archive: <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/">http://www.mail-archive.com/catalyst@lists.scsys.co.uk/</a>
Dev site: <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://dev.catalyst.perl.org/">http://dev.catalyst.perl.org/</a>
</pre>
</blockquote>
<br>
--
<br>
This message was scanned by ESVA and is believed to be clean.
<br>
<a moz-do-not-send="true"
href="http://antispam.infobal.com/cgi-bin/learn-msg.cgi?id=339762807E.4BF34">Click
here to report this message as spam.</a>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
List: <a class="moz-txt-link-abbreviated" href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a>
Listinfo: <a class="moz-txt-link-freetext" href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst</a>
Searchable archive: <a class="moz-txt-link-freetext" href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/">http://www.mail-archive.com/catalyst@lists.scsys.co.uk/</a>
Dev site: <a class="moz-txt-link-freetext" href="http://dev.catalyst.perl.org/">http://dev.catalyst.perl.org/</a>
</pre>
</blockquote>
</body>
</html>