From 063f6c7680093e9a740ad0196fc4e126eee77ca7 Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 21 May 2014 08:04:52 +0100 Subject: [PATCH] Only auto clear CLSI cache on hard error, otherwise prompt user --- .../app/coffee/Features/Compile/CompileManager.coffee | 11 +++++------ services/web/app/views/templates.jade | 8 ++++++-- services/web/public/coffee/pdf/CompiledView.coffee | 2 ++ .../coffee/Compile/CompileManagerTests.coffee | 8 ++++---- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/services/web/app/coffee/Features/Compile/CompileManager.coffee b/services/web/app/coffee/Features/Compile/CompileManager.coffee index a49338ed9b..b7f6ec1610 100644 --- a/services/web/app/coffee/Features/Compile/CompileManager.coffee +++ b/services/web/app/coffee/Features/Compile/CompileManager.coffee @@ -31,15 +31,14 @@ module.exports = CompileManager = DocumentUpdaterHandler.flushProjectToMongo project_id, (error) -> return callback(error) if error? ClsiManager.sendRequest project_id, (error, status, outputFiles) -> - return callback(error) if error? - logger.log files: outputFiles, "output files" - - if status == "failure" - # Sometimes compiles fail because the project gets in a broken - # state in LaTeX. So always clear cache on a failure. + if error? + # Sometimes compiles error because the project gets in a broken + # state in the CLSI. So always clear cache on an error. # Can do this in the background. ClsiManager.deleteAuxFiles project_id + return callback(error) + logger.log files: outputFiles, "output files" callback(null, status, outputFiles) diff --git a/services/web/app/views/templates.jade b/services/web/app/views/templates.jade index fd390f5922..3a53acdbbc 100644 --- a/services/web/app/views/templates.jade +++ b/services/web/app/views/templates.jade @@ -239,8 +239,12 @@ script(type="text/template")#compileFailedTemplate li.alert.alert-error - strong Ooops, your LaTeX code couldn't compile for some reason. Please check the errors below for details, or view the raw log. - + p + strong Compile Error. + span Sorry, your LaTeX code couldn't compile for some reason. Please check the errors below for details, or view the raw log. + p + | If the problem persists, try + a(href='#').js-clear-cache clearing the cache. script(type="text/template")#compileTimeoutTemplate li.alert.alert-error strong Timed out. diff --git a/services/web/public/coffee/pdf/CompiledView.coffee b/services/web/public/coffee/pdf/CompiledView.coffee index dd145984fc..582934c806 100644 --- a/services/web/public/coffee/pdf/CompiledView.coffee +++ b/services/web/public/coffee/pdf/CompiledView.coffee @@ -117,6 +117,8 @@ define [ errorLogs.prepend($(@templates.compileError)) else if !pdfExists errorLogs.prepend($(@templates.compileFailed)) + errorLogs.find(".js-clear-cache").on "click", () => + @options.manager.deleteCachedFiles() else if pdfExists && compileErrors.all.length == 0 errorLogs.prepend($(@templates.compileSuccess)) diff --git a/services/web/test/UnitTests/coffee/Compile/CompileManagerTests.coffee b/services/web/test/UnitTests/coffee/Compile/CompileManagerTests.coffee index 24de557aac..86ca4c4e8c 100644 --- a/services/web/test/UnitTests/coffee/Compile/CompileManagerTests.coffee +++ b/services/web/test/UnitTests/coffee/Compile/CompileManagerTests.coffee @@ -76,16 +76,16 @@ describe "CompileManager", -> .calledWith(project_id: @project_id, user_id: @user_id, "compiling project") .should.equal true - describe "when the compile fails", -> + describe "when the compile errors", -> beforeEach -> @CompileManager._checkIfAutoCompileLimitHasBeenHit = (_, cb)-> cb(null, true) @ClsiManager.deleteAuxFiles = sinon.stub() - @ClsiManager.sendRequest = sinon.stub().callsArgWith(1, null, @status = "failure") + @ClsiManager.sendRequest = sinon.stub().callsArgWith(1, @error = new Error("oops"), @status = "failure") @CompileManager.compile @project_id, @user_id, {}, @callback - it "should call the callback", -> + it "should call the callback with the error", -> @callback - .calledWith(null, @status) + .calledWith(@error) .should.equal true it "should clear the CLSI cache", ->