Skip to content

Commit ea5d4a8

Browse files
committed
improved exception handling
1 parent 59bee38 commit ea5d4a8

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

modules/ircd.module/ircd.pm

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ sub boot {
210210
$boot++;
211211
$::VERSION = $VERSION;
212212
$::notice_warnings = 1;
213+
$::notice_dies = 1;
213214

214215
# load mandatory boot stuff
215216
require POSIX;
@@ -281,7 +282,9 @@ sub startup_error {
281282

282283
# loop indefinitely
283284
sub loop {
284-
$loop->loop_forever;
285+
while (!eval { $loop->loop_once(undef); 1 }) {
286+
notice(event_loop_error => $@ || 'unknown error occurred in the event loop');
287+
}
285288
}
286289

287290
###################################
@@ -1088,11 +1091,21 @@ sub WARNING {
10881091
my $warn = shift;
10891092
return if $disable_warnings;
10901093
chomp $warn;
1091-
ircd->can('notice') && $::notice_warnings ?
1092-
notice(perl_warning => $warn) :
1094+
ircd->can('gnotice') && $::notice_warnings ?
1095+
gnotice(perl_warning => $warn) :
10931096
L($warn);
10941097
}
10951098

1099+
# handle uncaught exceptions
1100+
sub DIE {
1101+
my $err = shift;
1102+
return if $^S; # don't catch during eval
1103+
chomp $err;
1104+
ircd->can('gnotice') && $::notice_dies ?
1105+
gnotice(exception => "DIE: $err") :
1106+
L("uncaught exception: $err");
1107+
}
1108+
10961109
###############
10971110
### LOGGING ###
10981111
###############

0 commit comments

Comments
 (0)