[Dancer-users] Dancer logging stringifies some data

sawyer x xsawyerx at gmail.com
Fri Jun 22 01:39:05 CEST 2012

On Thu, Jun 21, 2012 at 7:00 PM, Ovid <curtis_ovid_poe at yahoo.com> wrote:

> Hi all,

Hi, :)

> I don't have the time to fix this right now, but we had a very interesting
> issue. I had this line in my code:
>   info "Bidding on auction $id", $bid;
> That turned out to be a massive bug!
> $bid is a hashref that gets serialized to JSON. Unfortunately, the act of
> printing out the data flipped one value from an NV (float) to a PV (string).

My familiarity with Perl internals is *very* limited (i.e., I don't know
nothing about it) but I think NV is simply a double, not necessarily a
floating point. Am I right ? (not that it matters)

Either way, it makes sense it would still stringify it.

>  That caused the JSON serializer render 1.2 as "1.2". Sadly, the system I
> was sending this data to reported a bizarre "Request throttled" error
> instead of a JSON validation error.


> The simple fix was to drop the $bid from the info() and add a test to
> ensure that I have a NV instead of a PV.

Out of interest, how did you perform that test?

> If anyone wants to look into this, that would be great. Perhaps adding
> optional cloning of the data in the logger prior to printing it out?
> (Optional because it might be expensive)

We can fix this in the format_message part of the abstract logging class.
However, loggers are not required to actually make use of format_message.
However, since loggers are not required to use it, it means that fixing it
there won't necessarily fix it on every logger.

We're open for any ideas on how to make it easier in Dancer 2, perhaps by
having the format_message come before the log() or after it, instead of
simply allowing the logger to use it and opt out of it if they don't want
to use it.

Either way, this seems like a stability bug and seems pretty important, so
I think we should fix it in Dancer 1 and force a value cloning whether
people want to or not. Right now it gives the value from the variable by
reference, so that explains the problem, because it keeps using by
reference onwards 'till the stringification.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.backup-manager.org/pipermail/dancer-users/attachments/20120622/2b68afcb/attachment.htm>

More information about the Dancer-users mailing list