From 50048a53b5b5d23437ccb859506c34b051e075ad Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 11 Feb 2015 11:34:49 +0000 Subject: [PATCH] Don't throw an exception if there is an error with unzip --- .../coffee/Features/Uploads/ArchiveManager.coffee | 12 +++++++++++- .../coffee/Uploads/ArchiveManagerTests.coffee | 13 +++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/services/web/app/coffee/Features/Uploads/ArchiveManager.coffee b/services/web/app/coffee/Features/Uploads/ArchiveManager.coffee index 75bf5d5dfe..e666b83f24 100644 --- a/services/web/app/coffee/Features/Uploads/ArchiveManager.coffee +++ b/services/web/app/coffee/Features/Uploads/ArchiveManager.coffee @@ -3,7 +3,11 @@ logger = require "logger-sharelatex" metrics = require "../../infrastructure/Metrics" module.exports = ArchiveManager = - extractZipArchive: (source, destination, callback = (err) ->) -> + extractZipArchive: (source, destination, _callback = (err) ->) -> + callback = (args...) -> + _callback(args...) + _callback = () -> + timer = new metrics.Timer("unzipDirectory") logger.log source: source, destination: destination, "unzipping file" @@ -18,6 +22,12 @@ module.exports = ArchiveManager = error ||= "" error += chunk + unzip.on "error", (err) -> + logger.error {err, source, destination}, "unzip failed" + if err.code == "ENOENT" + logger.error "unzip command not found. Please check the unzip command is installed" + callback(err) + unzip.on "exit", () -> timer.done() if error? diff --git a/services/web/test/UnitTests/coffee/Uploads/ArchiveManagerTests.coffee b/services/web/test/UnitTests/coffee/Uploads/ArchiveManagerTests.coffee index 5a484ccba2..d1f72a780e 100644 --- a/services/web/test/UnitTests/coffee/Uploads/ArchiveManagerTests.coffee +++ b/services/web/test/UnitTests/coffee/Uploads/ArchiveManagerTests.coffee @@ -57,3 +57,16 @@ describe "ArchiveManager", -> it "should log out the error", -> @logger.error.called.should.equal true + describe "with an error on the process", -> + beforeEach (done) -> + @ArchiveManager.extractZipArchive @source, @destination, (error) => + @callback(error) + done() + @process.emit "error", new Error("Something went wrong") + + it "should return the callback with an error", -> + @callback.calledWithExactly(new Error("Something went wrong")).should.equal true + + it "should log out the error", -> + @logger.error.called.should.equal true +