akshitkrnagpal / akshitkrnagpal/keyv-dataloader

Improve error handling in KeyvDataLoader class

Open
#5 0 comments 0 reactions 0 assignees View on GitHub
bug enhancement
Dominant language
TypeScript
Stars
1
Forks
0
PR merge metrics
No merged PRs in 30d

Description

After reviewing the code, I noticed potential improvements in the error handling logic of the KeyvDataLoader implementation.

### Issues
1. The current implementation doesn't properly handle errors that might occur when interacting with the cache layer.
2. There's no fallback mechanism if the cache fails but the database is available.

### Proposed Solution
1. Add try/catch blocks for cache operations to ensure cache errors don't break the entire functionality:

```typescript
// Example improvement for the set cache entries section
try {
await Promise.all(
entries.map((entry) =>
this.cache.set(entry.key, entry.value, entry.ttl)
)
);
} catch (error) {
// Log the error but continue execution
console.error('Failed to set cache entries:', error);
// Potentially add a cache health flag for future operations
}
```

2. Add a fallback option in constructor:

```typescript
export interface KeyvDataLoaderOptions {
// ... existing options

/**
* If true, fallback to batch loading on cache errors
*/
fallbackOnCacheError?: boolean;
}
```

These changes would make the library more resilient to cache layer failures and improve the overall reliability.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.