Merge pull request #2862 from overleaf/spd-flaky-oio-test

Fix flaky Open-in-Overleaf tests

GitOrigin-RevId: 7badb0e88b5c01478406e0cea3564d46e1b7a881
This commit is contained in:
Timothée Alby 2020-05-25 11:20:58 +02:00 committed by Copybot
parent 01c3e6e768
commit 345adb8ad2
2 changed files with 14 additions and 2 deletions

View file

@ -30,6 +30,8 @@ class InvalidNameError extends BackwardCompatibleError {}
class UnsupportedFileTypeError extends BackwardCompatibleError {}
class FileTooLargeError extends BackwardCompatibleError {}
class UnsupportedExportRecordsError extends BackwardCompatibleError {}
class V1HistoryNotSyncedError extends BackwardCompatibleError {}
@ -182,6 +184,7 @@ module.exports = {
TooManyRequestsError,
InvalidNameError,
UnsupportedFileTypeError,
FileTooLargeError,
UnsupportedExportRecordsError,
V1HistoryNotSyncedError,
ProjectHistoryDisabledError,

View file

@ -17,7 +17,7 @@ const _ = require('underscore')
const Settings = require('settings-sharelatex')
const request = require('request')
const { Transform, pipeline } = require('stream')
const { InvalidError } = require('../Features/Errors/Errors')
const { FileTooLargeError } = require('../Features/Errors/Errors')
const { promisifyAll } = require('../util/promises')
class SizeLimitedStream extends Transform {
@ -44,7 +44,7 @@ class SizeLimitedStream extends Transform {
this.bytes += chunk.length
if (this.sizeLimit && this.bytes > this.sizeLimit) {
return done(
new InvalidError({
new FileTooLargeError({
message: 'stream size limit reached',
info: { size: this.bytes }
})
@ -130,6 +130,15 @@ const FileWriter = {
}
pipeline(stream, passThrough, writeStream, function(err) {
if (
passThrough.bytes >= options.maxSizeBytes &&
!(err instanceof FileTooLargeError)
) {
err = new FileTooLargeError({
message: 'stream size limit reached',
info: { size: passThrough.bytes }
}).withCause(err || {})
}
if (err) {
logger.warn(
{ err, identifier, fsPath },