Skip to content

Commit

Permalink
fix: reject promise using Error and include error message
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Sep 13, 2016
1 parent 9e38b94 commit f1a5240
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ function findIdentityAsync (opts, identity) {
resolve(null)
}
})
.catch(function (err) {
debugerror(err)
reject(new Error('Error in finding identity. See details in debug log. (electron-osx-sign:error)'))
})
.catch(catchHandler('Error in finding identity', reject))
})
}

Expand Down Expand Up @@ -209,13 +206,16 @@ function validateOptsApplicationAsync (opts) {
.then(function () {
resolve(null)
})
.catch(function (err) {
debugerror(err)
reject(new Error('Application not found. See details in debug log. (electron-osx-sign:error)'))
})
.catch(catchHandler('Application not found', reject))
})
}

function catchHandler (prefix, reject) {
return function (error) {
reject(new Error(prefix + ': ' + (error.stack || error)))
}
}

/**
* This function returns a promise validating opts.binaries, the additional binaries to be signed along with the discovered enclosed components.
* @param {Object} opts - Options.
Expand Down Expand Up @@ -256,11 +256,8 @@ function validateOptsPlatformAsync (opts) {
opts.platform = platform
resolve(null)
})
.catch(function (err) {
// NB: This should logically not happen as detectElectronPlatformAsync should not give any rejections. However, it is put here just in case.
debugerror(err)
reject(new Error('Unable to decide Electron platform. See details in debug log. (electron-osx-sign:error)'))
})
// NB: This should logically not happen as detectElectronPlatformAsync should not give any rejections. However, it is put here just in case.
.catch(catchHandler('Unable to decide Electron platform', reject))
})
}

Expand All @@ -280,8 +277,7 @@ function verifySignApplicationAsync (opts) {
opts.app
], function (err, stdout, stderr) {
if (err) {
debugerror(err)
reject('Failed to verify application bundle. See details in debug log. (electron-osx-sign:error)')
catchHandler('Failed to verify application bundle', reject)(err)
return
}
debuglog('Result:\n' + stderr)
Expand All @@ -303,8 +299,7 @@ function verifySignApplicationAsync (opts) {
opts.app
], function (err, stdout, stderr) {
if (err) {
debugerror(err)
reject('Failed to pass Gatekeeper. See details in debug log. (electron-osx-sign:error)')
catchHandler('Failed to pass Gatekeeper: ', reject)(err)
return
}
debuglog('Result:\n' + stderr)
Expand Down

0 comments on commit f1a5240

Please sign in to comment.