From 51b69b10487d7cf272eac356c2eb2636c225f3ce Mon Sep 17 00:00:00 2001 From: Volpeon Date: Tue, 19 Oct 2021 21:23:35 +0200 Subject: Throw error if db fails to load --- src/services/postDatabase.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/services') diff --git a/src/services/postDatabase.ts b/src/services/postDatabase.ts index 63227a2..a782af8 100644 --- a/src/services/postDatabase.ts +++ b/src/services/postDatabase.ts @@ -2,6 +2,7 @@ import fs from "fs/promises"; import path from "path"; import * as f from "fp-ts"; import * as t from "io-ts"; +import * as tr from "io-ts/PathReporter"; export const PostDatabaseEntryC = t.type({ provider: t.literal("e926"), @@ -39,6 +40,8 @@ export class PostDatabase { if (f.either.isRight(entries)) { this.entries = this.max ? entries.right.slice(-1 * this.max) : entries.right; + } else { + throw new Error(tr.failure(entries.left).join("\n\n")); } } @@ -78,11 +81,6 @@ export class PostDatabase { await this.save(); return true; } - - async getCount() { - await this.load(); - return this.entries.length; - } } export default PostDatabase; -- cgit v1.2.3-70-g09d2