From: Mischa POSLAWSKY Date: Sun, 8 Mar 2015 05:15:11 +0000 (+0100) Subject: common: catch cookie set failure X-Git-Tag: v1.7~31 X-Git-Url: http://git.shiar.nl/sheet.git/commitdiff_plain/821e607e7760124765b4a5b00687990153d001ba common: catch cookie set failure Sometimes creation causes a fatal error which should be ignored until fixed. --- diff --git a/common.inc.plp b/common.inc.plp index ec6b0bf..563c0e4 100644 --- a/common.inc.plp +++ b/common.inc.plp @@ -25,15 +25,16 @@ sub stylesheet { if (exists $get{style}) { $style = $styles{ $get{style} }; - require CGI::Cookie; - if (my $cookie = CGI::Cookie->new( - -name => 'style', - -value => $style, - -path => '/', # site-wide; current page is confusing to most users - -expires => $style ? '+5y' : '-1d', - )) { + eval { + require CGI::Cookie; + my $cookie = CGI::Cookie->new( + -name => 'style', + -value => $style, + -path => '/', # site-wide; current page is confusing to most users + -expires => $style ? '+5y' : '-1d', + ) or die "empty object returned\n"; AddCookie($cookie->as_string); - } + } or warn "Unable to create style cookie: $@"; } $style ||= exists $cookie{style} && $styles{ $cookie{style} } || $_[0];