From 076c9c502d55df11c5dcb5443e790f372454f8fa Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sun, 2 May 2021 18:35:38 +0200 Subject: [PATCH] Add error handling in seed.ts Signed-off-by: David Mehren --- src/seed.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/seed.ts b/src/seed.ts index 0589a041f..b9f4b23bc 100644 --- a/src/seed.ts +++ b/src/seed.ts @@ -56,7 +56,16 @@ createConnection({ user.ownedNotes = [note]; await connection.manager.save([user, note, revision]); const foundUser = await connection.manager.findOne(User); + if (!foundUser) { + throw new Error('Could not find freshly seeded user. Aborting.'); + } const foundNote = await connection.manager.findOne(Note); + if (!foundNote) { + throw new Error('Could not find freshly seeded note. Aborting.'); + } + if (!foundNote.alias) { + throw new Error('Could not find alias of freshly seeded note. Aborting.'); + } const historyEntry = HistoryEntry.create(foundUser, foundNote); await connection.manager.save(historyEntry); console.log(`Created User '${foundUser.userName}'`);