SleeplessOne1917 / lemmy-bot

A bot library for Lemmy, the fediverse link aggregator.
https://www.npmjs.com/package/lemmy-bot
GNU Affero General Public License v3.0
93 stars 11 forks source link

Database init fails on first/second try #16

Open bwachter opened 1 year ago

bwachter commented 1 year ago

Works fine in memory, on disk tends to take one or two start attempts for it to finish initialisation.

Initializing DB
/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/db.js:43
const getRow = (db, id, table) => new Promise((resolve, reject) => {
                                  ^
Error: SQLITE_ERROR: no such table: posts
--> in Database#get('SELECT id, reprocessTime FROM posts WHERE id=?;', 54, [Function (anonymous)])
    at /home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/db.js:44:8
    at new Promise (<anonymous>)
    at getRow (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/db.js:43:35)
    at /home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/db.js:74:88
    at Generator.next (<anonymous>)
    at /home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/db.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/db.js:4:12)
    at get (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/db.js:74:26)
    at get (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/db.js:102:26)
    at LemmyBot.<anonymous> (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:988:35)
    at Generator.next (<anonymous>)
    at /home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:4:12)
    at LemmyBot._LemmyBot_handleEntry (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:987:12)
    at LemmyBot.<anonymous> (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:505:129)
    at Generator.next (<anonymous>)
    at /home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:4:12)
    at /home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:503:64
    at Array.map (<anonymous>)
    at LemmyBot.<anonymous> (/home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:503:46)
    at Generator.next (<anonymous>)
    at /home/bwachter/git/aard/lemmy-reddit-bot/node_modules/lemmy-bot/dist/bot.js:8:71
    at new Promise (<anonymous>) {
  errno: 1,
  code: 'SQLITE_ERROR',
  __augmented: true
}
SleeplessOne1917 commented 1 year ago

I'm unable to reproduce this issue. Did you create the file you wanted to use as a DB before starting the bot, or did you let the bot create it?

bwachter commented 1 year ago

I let the bot create it. I pretty reliably get this every time I remove the sqlite file before starting the bot. The code is here, if you want to have a look: https://github.com/r-sauna/lemmy-reddit-bot

SleeplessOne1917 commented 1 year ago

While I haven't gotten to running your bot I noticed that you're using a fork that is 18 commits behind the upstream and doesn't have the latest changes to support 0.18.x Lemmy instances. Do you still get the error if you update the dependency?

bwachter commented 1 year ago

I'll set up a dev environment to check that in a few days - but I'd guess it won't change anything: The reason I'm using the fork (and added the prepare script) was that I was hoping the issue was fixed in latest head at that point.

bwachter commented 1 year ago

It can create a DB now - I guess this got accidentally fixed by dropping websockets. I assume before events started coming in before the database was ready, which doesn't happen anymore.

Unfortunately with the new version I don't get any events coming in (and based on the issue tracker I'm not alone in that). I also get an error on startup when I'm using minutesBeforeRetryConnection in the connection options.

SleeplessOne1917 commented 9 months ago

@bwachter Do you still run into this issue? Your most recent comment mentions websockets, which were removed from Lemmy's API the better part of a year ago.