Skip Menu |

This queue is for tickets about the Log-Report CPAN distribution.

Report information
The Basics
Id: 123241
Status: resolved
Priority: 0/
Queue: Log-Report

People
Owner: Nobody in particular
Requestors: andy [...] andybev.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.23



Subject: Reporting an object
Date: Tue, 10 Oct 2017 19:40:09 +0100
To: bug-Log-Report [...] rt.cpan.org
From: Andrew Beverley <andy [...] andybev.com>
It would be useful if a message can be reported with something other than a Log::Report::* object. Otherwise, something like the following happens: Can't locate object method "to" via package "DBIx::Class::Exception" at /usr/share/perl5/Log/Report.pm line 121 Some additional logic around those lines to test for a blessed object that is not one of the specified names objects would work. Thanks, Andy
I cannot really see how you would end-up with calling the reporting functions with an object instead of the usual string. Maybe something should be fixed there as well. Other types of exceptions caught in a try block? We can improve handling a bit for any foreign object which stringifies nicely: --- lib/Log/Report.pm.old 2017-10-11 22:56:31.562159164 +0200 +++ lib/Log/Report.pm 2017-10-11 22:57:32.365818738 +0200 @@ -116,6 +116,11 @@ elsif($message->isa('Log::Report::Message')) { @_==0 or error __x"a message object is reported with more parameters"; } + else + { # foreign objects + @_%2 and error __x"odd length parameter list with '{msg}'", msg => $message; + $message = $lrm->new(_prepend => "$message", @_); + } if(my $to = $message->to) { @disp = grep $_->name eq $to, @disp; Also, objects with useful metadata could also be converted cleanly into LR::Message or LR::Exception objects. In the specific case of DBIx::Class::Exception, we could extract the location of the error nicely from the actual message. I think that code should go into LR::Dispatcher::Try where is also decodes Carp messages.
Subject: Re: [rt.cpan.org #123241] Reporting an object
Date: Thu, 12 Oct 2017 18:37:54 +0100
To: bug-Log-Report [...] rt.cpan.org
From: Andrew Beverley <andy [...] andybev.com>
Show quoted text
> I cannot really see how you would end-up with calling the reporting functions with an object > instead of the usual string. Maybe something should be fixed there as well.
Agreed. I can easily fix that, but it was more of a concern that it was happening and I hadn't noticed (as the normal logging died at that point). I haven't checked, but I *think* the offending code is similar to this: https://github.com/ctrlo/GADS/blob/c4cc56584790c0a4b897efd2e918b2c5aa711489/lib/GADS.pm#L85 Show quoted text
> We can improve handling a bit for any foreign object which stringifies nicely: > > --- lib/Log/Report.pm.old 2017-10-11 22:56:31.562159164 +0200 > +++ lib/Log/Report.pm 2017-10-11 22:57:32.365818738 +0200 > @@ -116,6 +116,11 @@ > elsif($message->isa('Log::Report::Message')) > { @_==0 or error __x"a message object is reported with more parameters"; > } > + else > + { # foreign objects > + @_%2 and error __x"odd length parameter list with '{msg}'", msg => $message; > + $message = $lrm->new(_prepend => "$message", @_); > + }
I think this is sensible, just to handle the situation cleanly in case it happens. Show quoted text
> Also, objects with useful metadata could also be converted cleanly into LR::Message or LR::Exception objects. > In the specific case of DBIx::Class::Exception, we could extract the location of the error nicely from the > actual message. I think that code should go into LR::Dispatcher::Try where is also decodes Carp messages.
Yes, now that would be nice :) Andy
Subject: Re: [rt.cpan.org #123241] Reporting an object
Date: Thu, 12 Oct 2017 19:50:21 +0200
To: Andrew Beverley via RT <bug-Log-Report [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Andrew Beverley via RT (bug-Log-Report@rt.cpan.org) [171012 17:38]: Show quoted text
> Queue: Log-Report > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=123241 > > > I haven't checked, but I *think* the offending code is similar to this: > https://github.com/ctrlo/GADS/blob/c4cc56584790c0a4b897efd2e918b2c5aa711489/lib/GADS.pm#L85
Don't see why you think that is related. I would change this: my $user_id = ref $self->user eq 'HASH' ? $self->user->{id} : $self->user->id; 'user_graphs.user_id' => $user_id, my $user = $self->user; 'user_graphs.user_id' => (blessed $user ? $user->id : $user->{id}), -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Subject: Re: [rt.cpan.org #123241] Reporting an object
Date: Thu, 12 Oct 2017 22:31:09 +0100
To: bug-Log-Report [...] rt.cpan.org
From: Andrew Beverley <andy [...] andybev.com>
On Thu, 12 Oct 2017 14:08:27 -0400 "Mark Overmeer via RT" wrote: Show quoted text
> > I haven't checked, but I *think* the offending code is similar to this: > > https://github.com/ctrlo/GADS/blob/c4cc56584790c0a4b897efd2e918b2c5aa711489/lib/GADS.pm#L85
> > Don't see why you think that is related.
Are you seeing the same as me? It should be a link to lib/GADS.pm line 85. I think it's what's raising the report (it defines a custom exception handling routine for DBIx::Class): schema->exception_action(sub { .. panic @_; Show quoted text
> I would change this: > > my $user_id = ref $self->user eq 'HASH' ? $self->user->{id} : $self->user->id; > 'user_graphs.user_id' => $user_id, > > my $user = $self->user; > 'user_graphs.user_id' => (blessed $user ? $user->id : $user->{id}),
Thanks, now changed :) Andy
Subject: Re: [rt.cpan.org #123241] Reporting an object
Date: Fri, 13 Oct 2017 09:57:09 +0200
To: Andrew Beverley via RT <bug-Log-Report [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Andrew Beverley via RT (bug-Log-Report@rt.cpan.org) [171012 21:31]: Show quoted text
> Queue: Log-Report > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=123241 > > > On Thu, 12 Oct 2017 14:08:27 -0400 "Mark Overmeer via RT" wrote:
> > > I haven't checked, but I *think* the offending code is similar to this: > > > https://github.com/ctrlo/GADS/blob/c4cc56584790c0a4b897efd2e918b2c5aa711489/lib/GADS.pm#L85
Show quoted text
> schema->exception_action(sub { > .. > panic @_;
Ah... cut-n-pasting long github links sometimes fails. schema->exception_action(sub { die $_[0] if $_[0] =~ /^Unable to satisfy requested constraint/; # Expected panic @_; # Not expected }); When panic complains that the message is an DBIx::Class::Exception object, then $_[0] matched with (hidden) overloaded stringification. Before you know it, this stringification is called many times. It might be clearer to write: schema->exception_action(sub { my ($exception) = @_; my $message = "$exception"; #XXX accessor is missing die $message if $message =~ /^Unable to satisfy requested constraint/; # Expected panic $message; # Not expected }); Looking at /home/perl/5.16.2/lib/site_perl/5.16.2/DBIx/Class/Exception.pm line 68, the $stacktrace parameter may add a function name before the message string. You regex may not catch all. I tried to produce the $message text for a regression test of parsing it, with this scriptlet: use DBIx::Class::Exception; my $stacktrace = 0; # or 1 sub f() { DBIx::Class::Exception->throw("help", $stacktrace) } sub g() { f() } g; I was surprised to see a stacktrace with the parameter with both 0 and 1. This is caused by DBIx/Class/Carp.pm line 53, which is called in the $stacktrace==0 case: sub __find_caller { [...] my $site = @f # if empty - nothing matched - full stack ? "at $f[1] line $f[2]" : Carp::longmess() help at /tmp/a.pl line 6. main::f() called at /tmp/a.pl line 8 main::g() called at /tmp/a.pl line 10 main::f(): help at /tmp/a.pl line 6. main::f() called at /tmp/a.pl line 8 main::g() called at /tmp/a.pl line 10 Also note the double blank after 'help' in the second case. The ::Exception parameter $stacktrace is not fulfilling its expectations, but I do not know which side should be fixed. Will you file a bugreport? Another bugreport could be filed for: use DBIx::Class::Exception; DBIx::Class::Exception->throw("help", 0); Which produces: {UNKNOWN}: help at /tmp/a.pl line 5. {UNKNOWN} is not the rights expression: the location is 'main' so the '{UNKNOWN}: ' can best be left out. -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Released