Skip to content

Commit

Permalink
Added cause to all lookup thrown errors for better debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikk221 committed Aug 7, 2024
1 parent cddde02 commit cefc328
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ class CachedLookup extends EventEmitter {
const in_flight = this.promises.get(identifier);
if (in_flight) return in_flight;

// Create a new cause Error to keep track of this error trace
const cause = new Error(`CachedLookup.fresh(${args.join(', ')}) -> lookup function threw an error.`);

// Initialize a new Promise to resolve the fresh value for this identifier
const promise = new Promise(async (resolve, reject) => {
// Attempt to resolve the value for the specified arguments from the lookup
Expand Down Expand Up @@ -325,6 +328,9 @@ class CachedLookup extends EventEmitter {
`CachedLookup.fresh(${args.join(', ')}) -> No value was returned by the lookup function.`
);

// Add the cause Error to the thrown error
error.cause = cause;

// Reject the fresh value promise with the error
reject(error);
}
Expand Down

0 comments on commit cefc328

Please sign in to comment.