import: Resolve error handling import causes instance crash

pull/4008/head^2
John McLear 2020-06-01 20:09:10 +01:00 committed by GitHub
parent 4497d37af9
commit addb9b957a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -74,6 +74,18 @@ async function doImport(req, res, padId)
form.uploadDir = tmpDirectory;
form.maxFileSize = settings.importMaxFileSize;
// Ref: https://github.com/node-formidable/formidable/issues/469
// Crash in Etherpad was Uploading Error: Error: Request aborted
// [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
form.onPart = part => {
form.handlePart(part);
if (part.filename !== undefined) {
form.openedFiles[form.openedFiles.length - 1]._writeStream.on('error', err => {
form.emit('error', err);
});
}
};
// locally wrapped Promise, since form.parse requires a callback
let srcFile = await new Promise((resolve, reject) => {
form.parse(req, function(err, fields, files) {
@ -84,7 +96,7 @@ async function doImport(req, res, padId)
}
// I hate doing indexOf here but I can't see anything to use...
if (err.stack.indexOf("maxFileSize") !== -1) {
if (err && err.stack && err.stack.indexOf("maxFileSize") !== -1) {
reject("maxFileSize");
}