Skip to content

[BUG] workbook-reader.js method parse is not watching error events when creating temporary file #1753

@pauliusg

Description

@pauliusg

🐛 Bug Report

In workbook-reader.js parse method we have this code:

await new Promise((resolve, reject) => {
  tmp.file((err, path, fd, tempFileCleanupCallback) => {
    if (err) {
      return reject(err);
    }
    waitingWorkSheets.push({sheetNo, path, tempFileCleanupCallback});

    const tempStream = fs.createWriteStream(path);
    entry.pipe(tempStream);
    return tempStream.on('finish', () => {
      return resolve();
    });
  });
});

tempStream is not watching error event, so if something happen when extracting worksheet from xlsx file to temp file, promise is not resolved and code stays in hanging state. We already had similar situation in our project :-(

Lib version: 4.2.1

Possible solution (optional, but very helpful):

You need to watch for error event and reject promise if error occurs [tempStream.on('error', reject);]:

await new Promise((resolve, reject) => {
  tmp.file((err, path, fd, tempFileCleanupCallback) => {
    if (err) {
      return reject(err);
    }
    waitingWorkSheets.push({sheetNo, path, tempFileCleanupCallback});

    const tempStream = fs.createWriteStream(path);
    tempStream.on('error', reject);
    entry.pipe(tempStream);
    return tempStream.on('finish', () => {
      return resolve();
    });
  });
});

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