From fb3cc5554c1913c6002c76bf3d12967bdde72d1f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 7 Jan 2015 10:19:09 -0800 Subject: [PATCH] Catch errors spawning squirrel Closes #4895 --- spec/squirrel-update-spec.coffee | 10 ++++++++++ src/browser/squirrel-update.coffee | 10 ++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/spec/squirrel-update-spec.coffee b/spec/squirrel-update-spec.coffee index 564760935..b71a9b0c4 100644 --- a/spec/squirrel-update-spec.coffee +++ b/spec/squirrel-update-spec.coffee @@ -25,6 +25,16 @@ describe "Windows squirrel updates", -> else originalSpawn('ls') + it "ignores errors spawning Squirrel", -> + jasmine.unspy(ChildProcess, 'spawn') + spyOn(ChildProcess, 'spawn').andCallFake -> throw new Error("EBUSY") + + app = quit: jasmine.createSpy('quit') + expect(SquirrelUpdate.handleStartupEvent(app, '--squirrel-install')).toBe true + + waitsFor -> + app.quit.callCount is 1 + it "quits the app on all squirrel events", -> app = quit: jasmine.createSpy('quit') diff --git a/src/browser/squirrel-update.coffee b/src/browser/squirrel-update.coffee index 70fc75bd9..2e5fec4d8 100644 --- a/src/browser/squirrel-update.coffee +++ b/src/browser/squirrel-update.coffee @@ -25,9 +25,15 @@ environmentKeyPath = 'HKCU\\Environment' # Spawn a command and invoke the callback when it completes with an error # and the output from standard out. spawn = (command, args, callback) -> - spawnedProcess = ChildProcess.spawn(command, args) - stdout = '' + + try + spawnedProcess = ChildProcess.spawn(command, args) + catch error + # Spawn can throw an error + process.nextTick -> callback?(error, stdout) + return + spawnedProcess.stdout.on 'data', (data) -> stdout += data error = null