Explorar o código

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

Fix flaky Open-in-Overleaf tests

GitOrigin-RevId: 7badb0e88b5c01478406e0cea3564d46e1b7a881
Timothée Alby %!s(int64=6) %!d(string=hai) anos
pai
achega
345adb8ad2

+ 3 - 0
services/web/app/src/Features/Errors/Errors.js

@@ -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,

+ 11 - 2
services/web/app/src/infrastructure/FileWriter.js

@@ -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 },