Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

450
Views
ERR Error: End of data reached (data length = 0, asked index = 4). Corrupted zip?

im making a whatsapp bot, im saving the chats in a excel file (im using exceljs) to read and handle some responses, i prefer to use promises and resolve them, i have a function to read chats:

const readChat = (number, message, step = null) =>
  new Promise((resolve, reject) => {
    setTimeout(() => {
      number = number.replace("@c.us", "");
      number = `${number}@c.us`;
      const pathExcel = `./chats/${number}.xlsx`;
      const workbook = new ExcelJS.Workbook();
      const today = moment().format("DD-MM-YYYY hh:mm");

      if (fs.existsSync(pathExcel)) {
        const workbook = new ExcelJS.Workbook();
        workbook.xlsx
          .readFile(pathExcel)
          .then(() => {
            const worksheet = workbook.getWorksheet(1);
            const lastRow = worksheet.lastRow;
            let getRowInsert = worksheet.getRow(++lastRow.number);
            getRowInsert.getCell("A").value = today;
            getRowInsert.getCell("B").value = message;

            if (step) {
              getRowInsert.getCell("C").value = step;
            }

            getRowInsert.commit();
            workbook.xlsx
              .writeFile(pathExcel)
              .then(() => {
                const getRowPrevStep = worksheet.getRow(lastRow.number);
                const lastStep = getRowPrevStep.getCell("C").value;
                resolve(lastStep);
              })
              .catch((err) => {
                console.log("ERR", err);
                reject("error");
              });
          })
          .catch((err) => {
            console.log("ERR", err);
            reject("error");
          });
      } else {
        const worksheet = workbook.addWorksheet("Chats");
        worksheet.columns = [
          { header: "Fecha", key: "number_customer" },
          { header: "Mensajes", key: "message" },
          { header: "Paso", key: "step" },
        ];

        step = step || "";

        worksheet.addRow([today, message, step]);
        workbook.xlsx
          .writeFile(pathExcel)
          .then(() => {
            resolve("STEP_1");
          })
          .catch((err) => {
            console.log("Error", err);
            reject("error");
          });
      }
    }, 1000);
  });

but the code after that else, its giving me the error: ERR Error: End of data reached (data length = 0, asked index = 4). Corrupted zip ?, the else, is supposed to be executed when there is no excel saved with that chat. I searched in many questions and pages, but i have not found any solution

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I believe you would get this error after you stop your execution in between, i.e when the file is getting updated and this would corrupt the excel file.

You could try adding a "try catch" around read file in your if condition and create a new copy of workbook whenever you get these particular errors ('End of data reached (data length = 0, asked index = 4). Corrupted zip ?' or 'File not found:')

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!