فهرست منبع

Don't throw fatal error when recently compiled

James Allen 10 سال پیش
والد
کامیت
9a0ec9c292

+ 2 - 1
services/web/app/coffee/Features/Compile/CompileManager.coffee

@@ -26,7 +26,8 @@ module.exports = CompileManager =
 			CompileManager._checkIfRecentlyCompiled project_id, user_id, (error, recentlyCompiled) ->
 			CompileManager._checkIfRecentlyCompiled project_id, user_id, (error, recentlyCompiled) ->
 				return callback(error) if error?
 				return callback(error) if error?
 				if recentlyCompiled
 				if recentlyCompiled
-					return callback new Error("project was recently compiled so not continuing")
+					logger.warn {project_id, user_id}, "project was recently compiled so not continuing"
+					return callback null, "too-recently-compiled", []
 				
 				
 				CompileManager._ensureRootDocumentIsSet project_id, (error) ->
 				CompileManager._ensureRootDocumentIsSet project_id, (error) ->
 					return callback(error) if error?
 					return callback(error) if error?

+ 5 - 8
services/web/test/UnitTests/coffee/Compile/CompileManagerTests.coffee

@@ -27,7 +27,7 @@ describe "CompileManager", ->
 				Timer: class Timer
 				Timer: class Timer
 					done: sinon.stub()
 					done: sinon.stub()
 				inc: sinon.stub()
 				inc: sinon.stub()
-			"logger-sharelatex": @logger = { log: sinon.stub() }
+			"logger-sharelatex": @logger = { log: sinon.stub(), warn: sinon.stub() }
 		@project_id = "mock-project-id-123"
 		@project_id = "mock-project-id-123"
 		@user_id = "mock-user-id-123"
 		@user_id = "mock-user-id-123"
 		@callback = sinon.stub()
 		@callback = sinon.stub()
@@ -90,15 +90,12 @@ describe "CompileManager", ->
 					.should.equal true
 					.should.equal true
 				
 				
 		describe "when the project has been recently compiled", ->
 		describe "when the project has been recently compiled", ->
-			beforeEach ->
+			it "should return", (done)->
 				@CompileManager._checkIfAutoCompileLimitHasBeenHit = (_, cb)-> cb(null, true)
 				@CompileManager._checkIfAutoCompileLimitHasBeenHit = (_, cb)-> cb(null, true)
 				@CompileManager._checkIfRecentlyCompiled = sinon.stub().callsArgWith(2, null, true)
 				@CompileManager._checkIfRecentlyCompiled = sinon.stub().callsArgWith(2, null, true)
-				@CompileManager.compile @project_id, @user_id, {}, @callback
-
-			it "should return the callback with an error", ->
-				@callback
-					.calledWith(new Error("project was recently compiled so not continuing"))
-					.should.equal true
+				@CompileManager.compile @project_id, @user_id, {}, (err, status)->
+					status.should.equal "too-recently-compiled"
+					done()
 
 
 		describe "should check the rate limit", ->
 		describe "should check the rate limit", ->
 			it "should return", (done)->
 			it "should return", (done)->