Error Object Null in Redis Caching Function
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 17.6k
- Forks
- 2k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 40
Description
Description
Issue Title: Error Object Null in Redis Caching Function
Issue Description:
I encountered an issue with the setCache function in my application while trying to cache data using Redis. The issue is that when an error occurs within the function, the error object is unexpectedly null, and the error details are not being logged or displayed properly in the catch block or console.log.
Reproduction Steps:
- Call the
setCachefunction with valid parameters. - Observe that an exception is thrown, but the
errorobject within the catch block isnull. - The expected behavior is that the error object should contain information about the error, including a stack trace and error message.
Code Sample:
export const client = createClient({url: Config.env(REDIS_CONNECTION_URL)});
export const setCache = async (key: string, value: unknown, defaultExpiration: number = null): Promise<void> => {
try {
if (defaultExpiration) {
await client.SET(key, JSON.stringify(value), {
EX: defaultExpiration
});
} else {
await client.SET(key, JSON.stringify(value));
}
} catch (error) {
console.log("Failed to insert item to redis", {
key,
value,
redisError: error,
defaultExpiration,
errorDebug: "try-catch"
});
}
};
Expected Behavior:
- When an error occurs during the Redis caching operation, the
catchblock should capture the error object with relevant error details. - The
console.logstatement within thecatchblock should output the error details, including error message and stack trace.
Actual Behavior:
- When an error occurs, the
catchblock is executed, but theerrorobject isnull. - The
console.logstatement outputs incomplete information, as theredisErrorfield containsnull.
Additional Information:
- I have verified that the Redis client is properly initialized and connected to the Redis server.
- I have tried logging the error using both
console.logandconsole.errorwithin thecatchblock, but the error object remainsnull.
Possible Solution:
I suspect that there might be an issue with the way the Redis client or the Promise rejection is being handled within the library. I've followed best practices for error handling and asynchronous programming, but the issue persists.
Node.js Version
v19.6.0
Redis Server Version
6.2.6
Node Redis Version
redis@4.6.7
Platform
macOS
Logs
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the setCache function shown in the issue and reproduce the reported catch-block output using node-redis 4.6.7, Node.js v19.6.0, and Redis 6.2.6. Inspect the SET rejection and logged redisError value; the issue is done when the cause is identified and a verified reproduction or documented resolution explains whether the error is produced by node-redis or the calling code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, redis, typescript
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100