Skip to content
This repository was archived by the owner on Jun 27, 2018. It is now read-only.

Commit 2a3887c

Browse files
authored
Merge pull request #227 from jonas-schievink/simpledebug
Make debugging playbot easier
2 parents 695965f + c3ed700 commit 2a3887c

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/bin/playbot.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use std::str;
1313
use std::sync::Arc;
1414
use std::thread;
1515
use std::u16;
16+
use std::panic::{AssertUnwindSafe, catch_unwind};
17+
use std::process;
1618

1719
use hyper::client::Client;
1820
use irc::client::prelude::*;
@@ -165,7 +167,7 @@ fn main() {{
165167
}
166168

167169
let command = &msg[1..];
168-
info!("<{}> {}", from, command);
170+
info!("{}: <{}> {}", chan, from, command);
169171
self.handle_cmd(chan, command);
170172
}
171173
}
@@ -226,10 +228,11 @@ fn main() {
226228
let server = server.as_table().unwrap();
227229

228230
for nick in server["nicks"].as_slice().unwrap() {
231+
let server_addr = server["server"].as_str().unwrap();
229232
let conf = Config {
230233
nickname: Some(String::from(nick.as_str().unwrap())),
231234
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)),
233236
port: server.get("port").map(|val| {
234237
let port = val.as_integer().unwrap();
235238
assert!(0 < port && port < u16::MAX as i64, "out of range for ports");
@@ -250,9 +253,17 @@ fn main() {
250253
shorten_key: bitly_key.clone(),
251254
cache: cache.clone(),
252255
};
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());
256267
}
257268
}
258269

0 commit comments

Comments
 (0)