@@ -13,6 +13,8 @@ use std::str;
13
13
use std:: sync:: Arc ;
14
14
use std:: thread;
15
15
use std:: u16;
16
+ use std:: panic:: { AssertUnwindSafe , catch_unwind} ;
17
+ use std:: process;
16
18
17
19
use hyper:: client:: Client ;
18
20
use irc:: client:: prelude:: * ;
@@ -165,7 +167,7 @@ fn main() {{
165
167
}
166
168
167
169
let command = & msg[ 1 ..] ;
168
- info ! ( "<{}> {}" , from, command) ;
170
+ info ! ( "{}: <{}> {}" , chan , from, command) ;
169
171
self . handle_cmd ( chan, command) ;
170
172
}
171
173
}
@@ -226,10 +228,11 @@ fn main() {
226
228
let server = server. as_table ( ) . unwrap ( ) ;
227
229
228
230
for nick in server[ "nicks" ] . as_slice ( ) . unwrap ( ) {
231
+ let server_addr = server[ "server" ] . as_str ( ) . unwrap ( ) ;
229
232
let conf = Config {
230
233
nickname : Some ( String :: from ( nick. as_str ( ) . unwrap ( ) ) ) ,
231
234
nick_password : server. get ( "password" ) . map ( |val| String :: from ( val. as_str ( ) . unwrap ( ) ) ) ,
232
- server : Some ( String :: from ( server [ "server" ] . as_str ( ) . unwrap ( ) ) ) ,
235
+ server : Some ( String :: from ( server_addr ) ) ,
233
236
port : server. get ( "port" ) . map ( |val| {
234
237
let port = val. as_integer ( ) . unwrap ( ) ;
235
238
assert ! ( 0 < port && port < u16 :: MAX as i64 , "out of range for ports" ) ;
@@ -250,9 +253,17 @@ fn main() {
250
253
shorten_key : bitly_key. clone ( ) ,
251
254
cache : cache. clone ( ) ,
252
255
} ;
253
- threads. push ( thread:: spawn ( move || {
254
- bot. main_loop ( ) ;
255
- } ) ) ;
256
+ threads. push ( thread:: Builder :: new ( )
257
+ . name ( format ! ( "{}@{}" , nick, server_addr) )
258
+ . spawn ( move || {
259
+ if let Err ( _) = catch_unwind ( AssertUnwindSafe ( || bot. main_loop ( ) ) ) {
260
+ error ! ( "killing playbot due to previous error" ) ;
261
+
262
+ // Abort the whole process, killing the other threads. This should make
263
+ // debugging easier since the other bots don't keep running.
264
+ process:: exit ( 101 ) ;
265
+ }
266
+ } ) . unwrap ( ) ) ;
256
267
}
257
268
}
258
269
0 commit comments