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 {
errored = true; result = await this.client.languageHandler.evalCode(parse);
return e.message; } catch (e) {
}) || '\n'; errored = true;
result = e.message;
}
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);
await this.kill(name); try {
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,16 +162,22 @@ 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;
} else { if (status !== 0 || error) {
resolve(data); if (!error) {
error = new Error(data || 'Something went wrong');
}
reject(error);
} else {
resolve(data);
}
} }
}); });
}); });