Masking warnings with eval/try in development mode?
Hello, I'm working on a website, currently in 'development' mode. The config has "warnings: 1", meaning "treat warnings as critical errors", which is what I want 99% of the time. However, there's one place were I want to try something that might fail, and proceed without stopping the dancer application. Something like: === get '/foobar' => sub { my $ok; eval { do_something_that_might_fail(); $ok = 1; }; template 'foobar', { ok => $ok } ; }; === However, in development mode with "warnings: 1", the "do_something" die()s and the dancer application stops with the standard HTTP 500 page with the stack trace. I don't want to turn "warnings" off, but I want to be able to mask this specific warning. Any ideas ? Thanks, -gordon
Hi, I guess you could always disable warnings locally, before your function call, and re-enable them after. Something like eval { no warnings; do_something_that_might_fail(); use warnings; $ok = 1; }; But then, yes, this means turning warnings off, but only for this specific function. Dunno if this helps Steph On Fri, Oct 12, 2012 at 10:51 PM, Assaf Gordon <gordon@cshl.edu> wrote:
Hello,
I'm working on a website, currently in 'development' mode. The config has "warnings: 1", meaning "treat warnings as critical errors", which is what I want 99% of the time.
However, there's one place were I want to try something that might fail, and proceed without stopping the dancer application.
Something like:
=== get '/foobar' => sub { my $ok; eval { do_something_that_might_fail(); $ok = 1; }; template 'foobar', { ok => $ok } ; }; ===
However, in development mode with "warnings: 1", the "do_something" die()s and the dancer application stops with the standard HTTP 500 page with the stack trace.
I don't want to turn "warnings" off, but I want to be able to mask this specific warning.
Any ideas ?
Thanks, -gordon _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
Stéphane Wenric wrote, On 10/15/2012 03:04 AM:
On Fri, Oct 12, 2012 at 10:51 PM, Assaf Gordon <gordon@cshl.edu <mailto:gordon@cshl.edu>> wrote:
However, in development mode with "warnings: 1", the "do_something" die()s and the dancer application stops with the standard HTTP 500 page with the stack trace.
I don't want to turn "warnings" off, but I want to be able to mask this specific warning.
I guess you could always disable warnings locally, before your function call, and re-enable them after. Something like
eval { no warnings; do_something_that_might_fail(); use warnings; $ok = 1; };
Unfortunately this doesn't work. Perhaps calling it "warning" is the wrong term, because the code in "do_something()" uses "die" (not "warn"), but adding "no warnings" has no effect - I still get the standard Dancer 500 error page with the stack-trace.
Assaf Gordon wrote, On 10/15/2012 11:53 AM:
Stéphane Wenric wrote, On 10/15/2012 03:04 AM:
On Fri, Oct 12, 2012 at 10:51 PM, Assaf Gordon <gordon@cshl.edu <mailto:gordon@cshl.edu>> wrote:
However, in development mode with "warnings: 1", the "do_something" die()s and the dancer application stops with the standard HTTP 500 page with the stack trace.
I don't want to turn "warnings" off, but I want to be able to mask this specific warning.
I guess you could always disable warnings locally, before your function call, and re-enable them after. Something like
no warnings;
Unfortunately this doesn't work.
Follow-up: locally disabling SIG{__WARN__} did the trick, eval { local $SIG{__WARN__}; do_something_that_might_fail(); $ok = 1; }; Based on this thread: http://www.perlmonks.org/?node_id=51097 But perhaps a better way is to update Dancer::Route::execute(), to check if we're inside an "eval" block, and if so - not "take over" and show error 500 ? (the "eval" implies that the programmer is aware of the possible failure and wants to handle it?)
On Mon, Oct 15, 2012 at 6:08 PM, Assaf Gordon <gordon@cshl.edu> wrote:
But perhaps a better way is to update Dancer::Route::execute(), to check if we're inside an "eval" block, and if so - not "take over" and show error 500 ? (the "eval" implies that the programmer is aware of the possible failure and wants to handle it?)
Not on version 1 though. We would appreciate help on making sure this isn't happening on Dancer 2.
participants (3)
-
Assaf Gordon -
sawyer x -
Stéphane Wenric