diff options
author | Volpeon <git@volpeon.ink> | 2021-10-19 21:23:35 +0200 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2021-10-19 21:23:35 +0200 |
commit | 51b69b10487d7cf272eac356c2eb2636c225f3ce (patch) | |
tree | b36c0372e01189d58e3a18641e378fdcc8775b3f /src/services | |
parent | Fix db (diff) | |
download | feralbot-51b69b10487d7cf272eac356c2eb2636c225f3ce.tar.gz feralbot-51b69b10487d7cf272eac356c2eb2636c225f3ce.tar.bz2 feralbot-51b69b10487d7cf272eac356c2eb2636c225f3ce.zip |
Throw error if db fails to load
Diffstat (limited to 'src/services')
-rw-r--r-- | src/services/postDatabase.ts | 8 |
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"; | |||
2 | import path from "path"; | 2 | import path from "path"; |
3 | import * as f from "fp-ts"; | 3 | import * as f from "fp-ts"; |
4 | import * as t from "io-ts"; | 4 | import * as t from "io-ts"; |
5 | import * as tr from "io-ts/PathReporter"; | ||
5 | 6 | ||
6 | export const PostDatabaseEntryC = t.type({ | 7 | export 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 | ||
88 | export default PostDatabase; | 86 | export default PostDatabase; |