Ignore all hook exceptions except in hook_checkout_prepare
A space had a custom plugin that died during hook_checkout, which caused the CHECKOUT lines to be logged without the corresponding BALANCE, and indeed no account balances were updated. While the plugin had a bug, it should not cause a half transaction in RevBank. After some hesitation, I went with ON ERROR RESUME NEXT because if a hook throws an exception, that should not interfere with other plugins (the hook can return ABORT if this it was intentional), including the calling plugin. An error message is printed (but not logged... TODO: add hook_plugin_fail to plugins/log) but the show must go on. During hook_checkout_prepare, however, nothing is set in stone yet, so this could be used for something that might die, and this instance of call_hooks() is now the one place where a failing hook should result in the transaction getting aborted. For this, call_hooks() now returns a success status boolean. Maybe it would make sense in more places, but I didn't identify any such calls yet. RevBank::Cart->checkout used to return a success status boolean, but it could just as well just die (indirectly, to abort the transaction) since it can't be called a second time within the same transaction anyway (because ->set_user must be called exactly once), so continuing with the same transaction can't result in anything useful anyway. In some places, error messages were slightly improved to contain a bit more information.
This commit is contained in:
parent
0c2b24bdc1
commit
52749df5f3
6 changed files with 27 additions and 20 deletions
|
@ -17,7 +17,7 @@ sub command :Tab(list,ls,shame,log,USERS) ($self, $cart, $command, @) {
|
|||
|
||||
return $self->balance($user) if not $cart->size;
|
||||
|
||||
$cart->checkout($user) or return REJECT, "Checkout failed.";
|
||||
$cart->checkout($user);
|
||||
|
||||
return ACCEPT;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue