Skip to content

fix: Fix xlsx.writeFile() not catching error when error occurs #2244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/xlsx/xlsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,8 @@ class XLSX {

this.write(stream, options).then(() => {
stream.end();
}).catch(err=>{
reject(err);
});
});
}
Expand Down
23 changes: 23 additions & 0 deletions spec/integration/pr/test-pr-2244.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const ExcelJS = verquire('exceljs');

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', // Non-existent file
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');
});
});