From 7c4ca745acafeb576342d30334cb2ca7f1e3fbf5 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Mon, 11 Nov 2019 21:00:41 -0500 Subject: [PATCH] error handling for ENOENT in parse --- src/commands/parse.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/commands/parse.ts b/src/commands/parse.ts index 1e8c1d7..ef2fef0 100644 --- a/src/commands/parse.ts +++ b/src/commands/parse.ts @@ -18,7 +18,13 @@ export default class Parse extends Command { if (!args.length) return this.client.commands.get('help').run(message, [this.name]); const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0].replace(/[<@!>]/gi, '') }] }); if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot find user.***`); - const dir = await fs.readdir(`/home/${account.username}/Validation`); + let dir: string[]; + try { + dir = await fs.readdir(`/home/${account.username}/Validation`); + } catch (err) { + return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot locate Validation directory.***`); + } + if (!dir.length) return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot locate certificate.***`); const cert = parseCert(`/home/${account.username}/Validation/${dir[0]}`); const subjectCommonName = cert.subject.commonName ? cert.subject.commonName : 'Not Specified'; const subjectEmailAddress = cert.subject.emailAddress ? cert.subject.emailAddress : 'Not Specified';