hubotio / hubot-redis-brain

A hubot script to persist hubot's brain using redis
69 stars 55 forks source link

Error when using string key prefix as part of REDIS_URL #58

Closed dgsangoma closed 1 year ago

dgsangoma commented 1 year ago

With hubot-redis-brain 1.1.6 / redis 4.6.7, using a REDIS_URL like "redis://redis.myhost.com:6379/my-bot-name" throws the following error:

[Mon Jul 24 2023 15:11:25 GMT+0000 (Coordinated Universal Time)] ERROR Unable to load /usr/src/app/node_modules/hubot-redis-brain/src/redis-brain: TypeError: Invalid pathname
  at Function.parseURL (/usr/src/app/node_modules/@redis/client/dist/lib/client/index.js:73:23)
  at Commander._RedisClient_initiateOptions (/usr/src/app/node_modules/@redis/client/dist/lib/client/index.js:350:36)
  at new RedisClient (/usr/src/app/node_modules/@redis/client/dist/lib/client/index.js:167:148)
  at new Commander (/usr/src/app/node_modules/@redis/client/dist/lib/commander.js:44:13)
  at create (/usr/src/app/node_modules/@redis/client/dist/lib/client/index.js:46:16)
  at Object.createClient (/usr/src/app/node_modules/redis/dist/index.js:38:38)
  at module.exports (/usr/src/app/node_modules/hubot-redis-brain/src/redis-brain.js:68:24)
  at Robot.loadFile (/usr/src/app/node_modules/hubot/src/robot.js:363:9)
  at module.exports (/usr/src/app/node_modules/hubot-redis-brain/index.js:7:9)
  at /usr/src/app/node_modules/hubot/src/robot.js:409:52
  at Array.forEach (<anonymous>:null:null)
  at Robot.loadExternalScripts (/usr/src/app/node_modules/hubot/src/robot.js:409:25)
  at /usr/src/app/node_modules/hubot/bin/hubot.js:203:13
  at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)

Looking into the redis source, it looks like the following code is the source of that error (https://github.com/redis/node-redis/blob/master/packages/client/lib/client/index.ts#L177-L184):

        if (pathname.length > 1) {
            const database = Number(pathname.substring(1));
            if (isNaN(database)) {
                throw new TypeError('Invalid pathname');
            }

            parsed.database = database;
        }

If I'm following correctly, it looks like the redis 4.x library only supports using a numeric value for the path prefix. Based on https://github.com/hubotio/hubot-redis-brain/commit/c1719baf78cfb5aa98c99dcb201d2dddc76cc516, it seems like non-numeric prefixes were intended to be supported by hubot-redis-brain, so I think something isn't quite right.

joeyguerra commented 1 year ago

I believe you're right. a valid Redis URL has a number (the database number) as the path and hubot-redis-brain assumes it's the prefix. I'll have to change the code and design to match that expectation.

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 2.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: