interchange / Dancer-Plugin-Interchange6

Dancer Plugin for Interchange6 shop machine
4 stars 1 forks source link

shop_cart->error fails in surprising fashion #36

Closed murwiz closed 9 years ago

murwiz commented 9 years ago

My code fragment looks like this:

shop_cart->update(param('sku'), param('quantity'));
my $err = shop_cart->error;

I was figuring to get back the 'Product for 2001 not found in cart.' message and act on it. However, instead I got back nothing, and my debug log had a dump listing of the shop_cart object! I spent some time digging around in this, and I hit on this which saved me from insanity:

http://www.perlmonks.org/?node_id=413799

(That's some old, old wisdom there.)

So I added:

debug coderef2name(shop_cart->can('error'));

Much to my surprise this printed out "Dancer::error". So by some bizarre quirk of inheritance, the "error" method supplied by (I think) Interchange6::Role::Errors is being replaced by Dancer::error!

SysPete commented 9 years ago

The error method in Cart has now been removed. Since in schema we always throw_exception the same approach is now used in IC6::Cart and we die instead of adding errors and returning.