summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolpeon <git@volpeon.ink>2021-10-19 21:23:35 +0200
committerVolpeon <git@volpeon.ink>2021-10-19 21:23:35 +0200
commit51b69b10487d7cf272eac356c2eb2636c225f3ce (patch)
treeb36c0372e01189d58e3a18641e378fdcc8775b3f
parentFix db (diff)
downloadferalbot-51b69b10487d7cf272eac356c2eb2636c225f3ce.tar.gz
feralbot-51b69b10487d7cf272eac356c2eb2636c225f3ce.tar.bz2
feralbot-51b69b10487d7cf272eac356c2eb2636c225f3ce.zip
Throw error if db fails to load
-rw-r--r--src/services/postDatabase.ts8
1 files changed, 3 insertions, 5 deletions
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";
2import path from "path"; 2import path from "path";
3import * as f from "fp-ts"; 3import * as f from "fp-ts";
4import * as t from "io-ts"; 4import * as t from "io-ts";
5import * as tr from "io-ts/PathReporter";
5 6
6export const PostDatabaseEntryC = t.type({ 7export const PostDatabaseEntryC = t.type({
7 provider: t.literal("e926"), 8 provider: t.literal("e926"),
@@ -39,6 +40,8 @@ export class PostDatabase {
39 40
40 if (f.either.isRight(entries)) { 41 if (f.either.isRight(entries)) {
41 this.entries = this.max ? entries.right.slice(-1 * this.max) : entries.right; 42 this.entries = this.max ? entries.right.slice(-1 * this.max) : entries.right;
43 } else {
44 throw new Error(tr.failure(entries.left).join("\n\n"));
42 } 45 }
43 } 46 }
44 47
@@ -78,11 +81,6 @@ export class PostDatabase {
78 await this.save(); 81 await this.save();
79 return true; 82 return true;
80 } 83 }
81
82 async getCount() {
83 await this.load();
84 return this.entries.length;
85 }
86} 84}
87 85
88export default PostDatabase; 86export default PostDatabase;