From 1e03b3a0db87360958c53e82301713f46ce53c42 Mon Sep 17 00:00:00 2001 From: linxl <3382272560@qq.com> Date: Fri, 14 Apr 2023 23:41:09 +0800 Subject: [PATCH 1/3] fix: Fix xlsx.writeFile() not catching error when error occurs --- lib/xlsx/xlsx.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/xlsx/xlsx.js b/lib/xlsx/xlsx.js index 4f6bc02c5..aace9a2df 100644 --- a/lib/xlsx/xlsx.js +++ b/lib/xlsx/xlsx.js @@ -675,6 +675,8 @@ class XLSX { this.write(stream, options).then(() => { stream.end(); + }).catch((err)=>{ + reject(err); }); }); } From 84417bd41bfa393fbf1d8ce13eeb132caddbc67a Mon Sep 17 00:00:00 2001 From: linxl <3382272560@qq.com> Date: Thu, 20 Apr 2023 08:25:45 +0800 Subject: [PATCH 2/3] temp submit --- spec/integration/pr/test-pr-2244.spec.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 spec/integration/pr/test-pr-2244.spec.js diff --git a/spec/integration/pr/test-pr-2244.spec.js b/spec/integration/pr/test-pr-2244.spec.js new file mode 100644 index 000000000..703b83bf0 --- /dev/null +++ b/spec/integration/pr/test-pr-2244.spec.js @@ -0,0 +1,24 @@ +const ExcelJS = verquire('exceljs'); + +describe('github 2244', () => { + it('pull request 2244', async () => { + async function test() { + const workbook = new ExcelJS.Workbook(); + const worksheet = workbook.addWorksheet('sheet'); + const imageId1 = workbook.addImage({ + filename: 'path/to/image.jpg', + extension: 'jpeg', + }); + worksheet.addImage(imageId1, 'B2:D6'); + await workbook.xlsx.writeFile('test.xlsx'); + } + let error; + try { + await test(); + } catch (err) { + error = err; + } + expect(error).to.be.an('error'); + // expect(test).to.throw(Error); + }); +}); From 3bf3500e3ab2b3fe19f59db1c0a8bb17b5f68e56 Mon Sep 17 00:00:00 2001 From: linxl <1658370535@qq.com> Date: Thu, 20 Apr 2023 09:56:16 +0800 Subject: [PATCH 3/3] Additional test cases and formatted writeFile code --- lib/xlsx/xlsx.js | 2 +- spec/integration/pr/test-pr-2244.spec.js | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/xlsx/xlsx.js b/lib/xlsx/xlsx.js index aace9a2df..268d1ddb3 100644 --- a/lib/xlsx/xlsx.js +++ b/lib/xlsx/xlsx.js @@ -675,7 +675,7 @@ class XLSX { this.write(stream, options).then(() => { stream.end(); - }).catch((err)=>{ + }).catch(err=>{ reject(err); }); }); diff --git a/spec/integration/pr/test-pr-2244.spec.js b/spec/integration/pr/test-pr-2244.spec.js index 703b83bf0..667446c4c 100644 --- a/spec/integration/pr/test-pr-2244.spec.js +++ b/spec/integration/pr/test-pr-2244.spec.js @@ -1,12 +1,12 @@ const ExcelJS = verquire('exceljs'); -describe('github 2244', () => { - it('pull request 2244', async () => { +describe('pull request 2244', () => { + it('pull request 2244- Fix xlsx.writeFile() not catching error when error occurs', async () => { async function test() { const workbook = new ExcelJS.Workbook(); const worksheet = workbook.addWorksheet('sheet'); const imageId1 = workbook.addImage({ - filename: 'path/to/image.jpg', + filename: 'path/to/image.jpg', // Non-existent file extension: 'jpeg', }); worksheet.addImage(imageId1, 'B2:D6'); @@ -19,6 +19,5 @@ describe('github 2244', () => { error = err; } expect(error).to.be.an('error'); - // expect(test).to.throw(Error); }); });
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: