Modify error handling
Exec errors shouldn't show up anymore
This commit is contained in:
parent
149d7025e8
commit
2cdec2aa2f
2 changed files with 33 additions and 14 deletions
|
@ -27,12 +27,15 @@ class MessageInvalidListener extends Listener {
|
|||
}
|
||||
|
||||
let errored = false;
|
||||
const result = await this.client.languageHandler.evalCode(parse)
|
||||
.catch(e => {
|
||||
let result;
|
||||
try {
|
||||
result = await this.client.languageHandler.evalCode(parse);
|
||||
} catch (e) {
|
||||
errored = true;
|
||||
return e.message;
|
||||
}) || '\n';
|
||||
result = e.message;
|
||||
}
|
||||
|
||||
result = result || '';
|
||||
if (!message.guild || message.channel.permissionsFor(this.client.user).has('ADD_REACTIONS')) {
|
||||
if (reaction) {
|
||||
reaction.users.remove();
|
||||
|
|
|
@ -129,7 +129,14 @@ class LanguageHandler extends AkairoHandler {
|
|||
return result;
|
||||
} catch (err) {
|
||||
this.containers.delete(dockerID);
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
@ -137,13 +144,16 @@ class LanguageHandler extends AkairoHandler {
|
|||
|
||||
handleSpawn(proc, timeout = null) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let handled = false;
|
||||
if (timeout !== null) {
|
||||
setTimeout(() => {
|
||||
handled = true;
|
||||
reject(new Error('Timed out'));
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
let data = '';
|
||||
let error;
|
||||
proc.stdout.on('data', chunk => {
|
||||
data += chunk;
|
||||
});
|
||||
|
@ -152,17 +162,23 @@ class LanguageHandler extends AkairoHandler {
|
|||
data += chunk;
|
||||
});
|
||||
|
||||
proc.on('error', error => {
|
||||
error.data = data;
|
||||
reject(error);
|
||||
proc.on('error', e => {
|
||||
error = e;
|
||||
});
|
||||
|
||||
proc.on('exit', status => {
|
||||
if (status !== 0) {
|
||||
reject(new Error(data));
|
||||
proc.on('close', status => {
|
||||
if (!handled) {
|
||||
handled = true;
|
||||
if (status !== 0 || error) {
|
||||
if (!error) {
|
||||
error = new Error(data || 'Something went wrong');
|
||||
}
|
||||
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(data);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue