Don't throw an exception if there is an error with unzip

This commit is contained in:
James Allen 2015-02-11 11:34:49 +00:00
parent bf38fb7459
commit 50048a53b5
2 changed files with 24 additions and 1 deletions

View file

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

View file

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