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

[FEATURE] Add more context in error messages #39

@kellyselden

Description

@kellyselden

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions