From dd70829659e8ce255db8d266912972b2266b24e3 Mon Sep 17 00:00:00 2001 From: Alexandre Morignot <erdnaxeli@cervoi.se> Date: Tue, 17 Feb 2015 15:18:20 +0100 Subject: [PATCH] Sam::commands::edit errors handling --- Sam/commands/edit.pm | 17 +++++++---------- Sam/commands/parser.pm | 11 ++++++++++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Sam/commands/edit.pm b/Sam/commands/edit.pm index 9781940..221a80d 100644 --- a/Sam/commands/edit.pm +++ b/Sam/commands/edit.pm @@ -1,4 +1,4 @@ -package Sam::Sam::commands::edit; +package Sam::commands::edit; require Exporter; our @ISA = qw(Exporter); @@ -20,7 +20,7 @@ sub exec { if ($command eq "lien" or $command eq "url" or $command eq "link") { if ($arg !~ /^$RE{URI}{HTTP}{-scheme => qr(https?)}$/) { - $irc->yield(privmsg => $chan => "Ce n'est pas une url valide"); + die "Ce n'est pas une URL valide"; } else { eval { @@ -28,25 +28,22 @@ sub exec { $sth->execute($arg, $id); if ($sth->rows == 0) { - $irc->yield(privmsg => $chan => "Aucune soirée trouvée avec cet identifiant"); - } - else { - $irc->yield(privmsg => $chan => "Oui chef !"); + die "Aucune soirée trouvée avec cet identifiant"; } $dbh->commit; }; if ($@) { - $log->error("Quelque chose a chié dans la transaction : $@"); + $log->error("$@"); $dbh->rollback; - - $irc->yield(privmsg => $chan => "Erreur, commande non exécutée"); + + die $@; } } } else { - $irc->yield(privmsg => $chan => "Commande inconnue"); + die "Commande inconnue"; } $dbh->{AutoCommit} = $saveCommit; diff --git a/Sam/commands/parser.pm b/Sam/commands/parser.pm index a28df21..3824e49 100644 --- a/Sam/commands/parser.pm +++ b/Sam/commands/parser.pm @@ -84,7 +84,16 @@ sub exec { my $command = $2; my $arg = $3; - Sam::commands::edit::exec($id, $command, $arg, $chan); + eval { + Sam::commands::edit::exec($id, $command, $arg, $chan); + }; + + if ($@) { + $irc->yield(privmsg => $chan => "Erreur : $@"); + } + else { + $irc->yield(privmsg => $chan => "Oui chef !"); + } } elsif ($msg =~ /^Sam(?:,|:) +j'y +vais/) { Sam::commands::addUser::exec($nick, $lastID->{$chan->[0]}, $chan); -- GitLab