Modify error handling

Exec errors shouldn't show up anymore
This commit is contained in:
1computer1 2019-05-21 11:21:18 -04:00
parent 149d7025e8
commit 2cdec2aa2f
2 changed files with 33 additions and 14 deletions

View file

@ -27,12 +27,15 @@ class MessageInvalidListener extends Listener {
} }
let errored = false; let errored = false;
const result = await this.client.languageHandler.evalCode(parse) let result;
.catch(e => { try {
result = await this.client.languageHandler.evalCode(parse);
} catch (e) {
errored = true; errored = true;
return e.message; result = e.message;
}) || '\n'; }
result = result || '';
if (!message.guild || message.channel.permissionsFor(this.client.user).has('ADD_REACTIONS')) { if (!message.guild || message.channel.permissionsFor(this.client.user).has('ADD_REACTIONS')) {
if (reaction) { if (reaction) {
reaction.users.remove(); reaction.users.remove();

View file

@ -129,7 +129,14 @@ class LanguageHandler extends AkairoHandler {
return result; return result;
} catch (err) { } catch (err) {
this.containers.delete(dockerID); this.containers.delete(dockerID);
try {
await this.kill(name); await this.kill(name);
} catch (err2) {
// Kill did not work, usually this is because of the container being killed just before.
// Happens when evals are done in quick succession and the container can't handle it.
// Solution is to lower the concurrent setting for that compiler.
}
throw err; throw err;
} }
}); });
@ -137,13 +144,16 @@ class LanguageHandler extends AkairoHandler {
handleSpawn(proc, timeout = null) { handleSpawn(proc, timeout = null) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let handled = false;
if (timeout !== null) { if (timeout !== null) {
setTimeout(() => { setTimeout(() => {
handled = true;
reject(new Error('Timed out')); reject(new Error('Timed out'));
}, timeout); }, timeout);
} }
let data = ''; let data = '';
let error;
proc.stdout.on('data', chunk => { proc.stdout.on('data', chunk => {
data += chunk; data += chunk;
}); });
@ -152,17 +162,23 @@ class LanguageHandler extends AkairoHandler {
data += chunk; data += chunk;
}); });
proc.on('error', error => { proc.on('error', e => {
error.data = data; error = e;
reject(error);
}); });
proc.on('exit', status => { proc.on('close', status => {
if (status !== 0) { if (!handled) {
reject(new Error(data)); handled = true;
if (status !== 0 || error) {
if (!error) {
error = new Error(data || 'Something went wrong');
}
reject(error);
} else { } else {
resolve(data); resolve(data);
} }
}
}); });
}); });
} }