Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

[FEATURE] Add more context in error messages #39

Open
kellyselden opened this issue Apr 8, 2021 · 0 comments
Open

[FEATURE] Add more context in error messages #39

kellyselden opened this issue Apr 8, 2021 · 0 comments

Comments

@kellyselden
Copy link

What / Why

It would be great if the reason the lock couldn't be acquired could be included in the error message. I thought there was something wrong with my implementation because I would intermittently see Error: EEXIST: file already exists, open 'xxx' in my logs. After extensive debugging, I realised it was working as designed, it was just timing out after the wait has expired.

I added the following workaround code:

  let wait = 60e3;

  let before = new Date();

  try {
    await lock(lockFilePath, { wait });
  } catch (err) {
    let elapsed = new Date() - before;

    if (err.code === 'EEXIST' && elapsed >= wait) {
      err = new Error(`\`${lock.name}\` failed to acquire lock after ${elapsed}ms. ${err.message}`);
    }

    throw err;
  }

It would be great if we could include all this context as to why it failed into the error message.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant