Use ::pCatch(noop) instead of .catch(noop).

Avoid hiding programmer errors.
This commit is contained in:
Julien Fontanet 2016-03-04 11:21:31 +01:00
parent 6406bb7fb6
commit 6aba73f970
8 changed files with 48 additions and 39 deletions

View File

@ -1,4 +1,7 @@
import { noop } from '../utils' import {
noop,
pCatch
} from '../utils'
export async function add ({ export async function add ({
host, host,
@ -11,7 +14,7 @@ export async function add ({
if (autoConnect) { if (autoConnect) {
// Connect asynchronously, ignore any errors. // Connect asynchronously, ignore any errors.
this.connectXenServer(server.id).catch(noop) this.connectXenServer(server.id)::pCatch(noop)
} }
return server.id return server.id
@ -96,7 +99,7 @@ set.params = {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
export async function connect ({id}) { export async function connect ({id}) {
this.updateXenServer(id, {enabled: true}).catch(noop) this.updateXenServer(id, {enabled: true})::pCatch(noop)
await this.connectXenServer(id) await this.connectXenServer(id)
} }
@ -113,7 +116,7 @@ connect.params = {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
export async function disconnect ({id}) { export async function disconnect ({id}) {
this.updateXenServer(id, {enabled: false}).catch(noop) this.updateXenServer(id, {enabled: false})::pCatch(noop)
await this.disconnectXenServer(id) await this.disconnectXenServer(id)
} }

View File

@ -24,6 +24,7 @@ startsWith = require 'lodash.startswith'
noop, noop,
parseSize, parseSize,
parseXml, parseXml,
pCatch,
pFinally pFinally
} = require '../utils' } = require '../utils'
{isVmRunning: $isVMRunning} = require('../xapi') {isVmRunning: $isVMRunning} = require('../xapi')
@ -277,7 +278,7 @@ delete_ = ({vm, delete_disks: deleteDisks}) ->
@releaseLimitsInResourceSet( @releaseLimitsInResourceSet(
@computeVmResourcesUsage(vm), @computeVmResourcesUsage(vm),
resourceSet resourceSet
).catch(noop) )::pCatch(noop)
return xapi.deleteVm(vm._xapiId, deleteDisks) return xapi.deleteVm(vm._xapiId, deleteDisks)

View File

@ -9,6 +9,7 @@ import {
import { import {
addChecksumToReadStream, addChecksumToReadStream,
noop, noop,
pCatch,
validChecksumOfReadStream validChecksumOfReadStream
} from '../utils' } from '../utils'
@ -90,7 +91,7 @@ export default class RemoteHandlerAbstract {
await eventToPromise(stream, 'readable') await eventToPromise(stream, 'readable')
if (stream.length === undefined) { if (stream.length === undefined) {
stream.length = await this.getSize(file).catch(noop) stream.length = await this.getSize(file)::pCatch(noop)
} }
return stream return stream
@ -157,7 +158,7 @@ export default class RemoteHandlerAbstract {
checksum = false checksum = false
} = {}) { } = {}) {
if (checksum) { if (checksum) {
this._unlink(`${file}.checksum`).catch(noop) this._unlink(`${file}.checksum`)::pCatch(noop)
} }
return this._unlink(file) return this._unlink(file)

View File

@ -381,7 +381,7 @@ export default class Xapi extends XapiBase {
return value === null return value === null
? removal ? removal
: removal.catch(noop).then(() => this.call(add, ref, name, prepareXapiParam(value))) : removal::pCatch(noop).then(() => this.call(add, ref, name, prepareXapiParam(value)))
} }
})) }))
} }
@ -861,7 +861,7 @@ export default class Xapi extends XapiBase {
let ref let ref
try { try {
ref = await this.call('VM.snapshot_with_quiesce', vm.$ref, nameLabel) ref = await this.call('VM.snapshot_with_quiesce', vm.$ref, nameLabel)
this.addTag(ref, 'quiesce').catch(noop) // ignore any failures this.addTag(ref, 'quiesce')::pCatch(noop) // ignore any failures
} catch (error) { } catch (error) {
if ( if (
error.code !== 'VM_SNAPSHOT_WITH_QUIESCE_NOT_SUPPORTED' && error.code !== 'VM_SNAPSHOT_WITH_QUIESCE_NOT_SUPPORTED' &&
@ -1064,7 +1064,7 @@ export default class Xapi extends XapiBase {
// Removes disks from the provision XML, we will create them by // Removes disks from the provision XML, we will create them by
// ourselves. // ourselves.
await this.call('VM.remove_from_other_config', vm.$ref, 'disks').catch(noop) await this.call('VM.remove_from_other_config', vm.$ref, 'disks')::pCatch(noop)
// Creates the VDIs and executes the initial steps of the // Creates the VDIs and executes the initial steps of the
// installation. // installation.
@ -1216,14 +1216,14 @@ export default class Xapi extends XapiBase {
vdi.VBDs.length < 2 || vdi.VBDs.length < 2 ||
every(vdi.$VBDs, vbd => vbd.VM === vm.$ref) every(vdi.$VBDs, vbd => vbd.VM === vm.$ref)
) { ) {
return this._deleteVdi(vdi).catch(noop) return this._deleteVdi(vdi)::pCatch(noop)
} }
console.error(`cannot delete VDI ${vdi.name_label} (from VM ${vm.name_label})`) console.error(`cannot delete VDI ${vdi.name_label} (from VM ${vm.name_label})`)
})) }))
} }
await Promise.all(mapToArray(vm.$snapshots, snapshot => { await Promise.all(mapToArray(vm.$snapshots, snapshot => {
return this.deleteVm(snapshot.$id, true).catch(noop) return this.deleteVm(snapshot.$id, true)::pCatch(noop)
})) }))
await this.call('VM.destroy', vm.$ref) await this.call('VM.destroy', vm.$ref)
@ -1267,7 +1267,7 @@ export default class Xapi extends XapiBase {
const taskRef = await this._createTask('VM Export', vm.name_label) const taskRef = await this._createTask('VM Export', vm.name_label)
if (snapshotRef) { if (snapshotRef) {
this._watchTask(taskRef)::pFinally(() => { this._watchTask(taskRef)::pFinally(() => {
this.deleteVm(snapshotRef, true).catch(noop) this.deleteVm(snapshotRef, true)::pCatch(noop)
}) })
} }
@ -1293,7 +1293,7 @@ export default class Xapi extends XapiBase {
if (snapshotNameLabel) { if (snapshotNameLabel) {
this._setObjectProperties(vm, { this._setObjectProperties(vm, {
nameLabel: snapshotNameLabel nameLabel: snapshotNameLabel
}).catch(noop) })::pCatch(noop)
} }
const baseVm = baseVmId && this.getObject(baseVmId) const baseVm = baseVmId && this.getObject(baseVmId)
@ -1431,7 +1431,7 @@ export default class Xapi extends XapiBase {
// 2. Delete all VBDs which may have been created by the import. // 2. Delete all VBDs which may have been created by the import.
await Promise.all(mapToArray( await Promise.all(mapToArray(
vm.$VBDs, vm.$VBDs,
vbd => this._deleteVbd(vbd).catch(noop) vbd => this._deleteVbd(vbd)::pCatch(noop)
)) ))
// 3. Create VDIs. // 3. Create VDIs.
@ -1510,7 +1510,7 @@ export default class Xapi extends XapiBase {
]) ])
if (deleteBase && baseVm) { if (deleteBase && baseVm) {
this._deleteVm(baseVm, true).catch(noop) this._deleteVm(baseVm, true)::pCatch(noop)
} }
await Promise.all([ await Promise.all([
@ -1604,7 +1604,7 @@ export default class Xapi extends XapiBase {
if (onVmCreation) { if (onVmCreation) {
this._waitObject( this._waitObject(
obj => obj && obj.current_operations && taskRef in obj.current_operations obj => obj && obj.current_operations && taskRef in obj.current_operations
).then(onVmCreation).catch(noop) ).then(onVmCreation)::pCatch(noop)
} }
const [ vmRef ] = await Promise.all([ const [ vmRef ] = await Promise.all([
@ -1776,10 +1776,10 @@ export default class Xapi extends XapiBase {
} finally { } finally {
this._setObjectProperties(vm, { this._setObjectProperties(vm, {
PV_bootloader: bootloader PV_bootloader: bootloader
}).catch(noop) })::pCatch(noop)
forEach(bootables, ([ vbd, bootable ]) => { forEach(bootables, ([ vbd, bootable ]) => {
this._setObjectProperties(vbd, { bootable }).catch(noop) this._setObjectProperties(vbd, { bootable })::pCatch(noop)
}) })
} }
} }
@ -1976,7 +1976,7 @@ export default class Xapi extends XapiBase {
throw error throw error
} }
await this.call('VBD.eject', cdDrive.$ref).catch(noop) await this.call('VBD.eject', cdDrive.$ref)::pCatch(noop)
// Retry. // Retry.
await this.call('VBD.insert', cdDrive.$ref, cd.$ref) await this.call('VBD.insert', cdDrive.$ref, cd.$ref)
@ -2015,7 +2015,7 @@ export default class Xapi extends XapiBase {
} }
async _deleteVbd (vbd) { async _deleteVbd (vbd) {
await this._disconnectVbd(vbd).catch(noop) await this._disconnectVbd(vbd)::pCatch(noop)
await this.call('VBD.destroy', vbd.$ref) await this.call('VBD.destroy', vbd.$ref)
} }
@ -2023,7 +2023,7 @@ export default class Xapi extends XapiBase {
async destroyVbdsFromVm (vmId) { async destroyVbdsFromVm (vmId) {
await Promise.all( await Promise.all(
mapToArray(this.getObject(vmId).$VBDs, async vbd => { mapToArray(this.getObject(vmId).$VBDs, async vbd => {
await this.disconnectVbd(vbd.$ref).catch(noop) await this.disconnectVbd(vbd.$ref)::pCatch(noop)
return this.call('VBD.destroy', vbd.$ref) return this.call('VBD.destroy', vbd.$ref)
}) })
) )
@ -2099,7 +2099,7 @@ export default class Xapi extends XapiBase {
response.cancel = (cancel => () => { response.cancel = (cancel => () => {
return new Promise(resolve => { return new Promise(resolve => {
resolve(cancel()) resolve(cancel())
}).then(() => task.catch(noop)) }).then(() => task::pCatch(noop))
})(response.cancel) })(response.cancel)
response.task = task response.task = task

View File

@ -5,6 +5,7 @@ import {
import { import {
createRawObject, createRawObject,
generateToken, generateToken,
pCatch,
noop noop
} from '../utils' } from '../utils'
@ -166,7 +167,7 @@ export default class {
if (!( if (!(
token.expiration > Date.now() token.expiration > Date.now()
)) { )) {
this._tokens.remove(id).catch(noop) this._tokens.remove(id)::pCatch(noop)
throw new NoSuchAuthenticationToken(id) throw new NoSuchAuthenticationToken(id)
} }

View File

@ -20,6 +20,7 @@ import {
forEach, forEach,
mapToArray, mapToArray,
noop, noop,
pCatch,
pSettle, pSettle,
safeDateFormat safeDateFormat
} from '../utils' } from '../utils'
@ -151,7 +152,7 @@ export default class {
// Once done, (asynchronously) remove the (now obsolete) local // Once done, (asynchronously) remove the (now obsolete) local
// base. // base.
if (localBaseUuid) { if (localBaseUuid) {
promise.then(() => srcXapi.deleteVm(localBaseUuid, true)).catch(noop) promise.then(() => srcXapi.deleteVm(localBaseUuid, true))::pCatch(noop)
} }
// (Asynchronously) Identify snapshot as future base. // (Asynchronously) Identify snapshot as future base.
@ -159,7 +160,7 @@ export default class {
return srcXapi._updateObjectMapProperty(srcVm, 'other_config', { return srcXapi._updateObjectMapProperty(srcVm, 'other_config', {
[TAG_LAST_BASE_DELTA]: delta.vm.uuid [TAG_LAST_BASE_DELTA]: delta.vm.uuid
}) })
}).catch(noop) })::pCatch(noop)
return promise return promise
})() })()
@ -306,7 +307,7 @@ export default class {
const base = bases.pop() const base = bases.pop()
// Remove old bases if exists. // Remove old bases if exists.
Promise.all(mapToArray(bases, base => xapi.deleteVdi(base.$id))).catch(noop) Promise.all(mapToArray(bases, base => xapi.deleteVdi(base.$id)))::pCatch(noop)
// It is strange to have no base but a full backup ! // It is strange to have no base but a full backup !
// A full is necessary if it not exists backups or // A full is necessary if it not exists backups or
@ -340,8 +341,8 @@ export default class {
]) ])
} catch (error) { } catch (error) {
// Remove new backup. (corrupt) and delete new vdi base. // Remove new backup. (corrupt) and delete new vdi base.
xapi.deleteVdi(currentSnapshot.$id).catch(noop) xapi.deleteVdi(currentSnapshot.$id)::pCatch(noop)
await handler.unlink(backupFullPath, { checksum: true }).catch(noop) await handler.unlink(backupFullPath, { checksum: true })::pCatch(noop)
throw error throw error
} }
@ -440,7 +441,7 @@ export default class {
const { newBaseId, backupDirectory, vdiFilename } = vdiBackup.value() const { newBaseId, backupDirectory, vdiFilename } = vdiBackup.value()
await xapi.deleteVdi(newBaseId) await xapi.deleteVdi(newBaseId)
await handler.unlink(`${dir}/${backupDirectory}/${vdiFilename}`, { checksum: true }).catch(noop) await handler.unlink(`${dir}/${backupDirectory}/${vdiFilename}`, { checksum: true })::pCatch(noop)
}) })
) )
} }
@ -534,7 +535,7 @@ export default class {
await handler.outputFile(infoPath, JSON.stringify(info, null, 2), {flag: 'wx'}) await handler.outputFile(infoPath, JSON.stringify(info, null, 2), {flag: 'wx'})
} catch (e) { } catch (e) {
await Promise.all([ await Promise.all([
handler.unlink(infoPath).catch(noop), handler.unlink(infoPath)::pCatch(noop),
this._failedRollingDeltaVmBackup(xapi, handler, dir, fulFilledVdiBackups) this._failedRollingDeltaVmBackup(xapi, handler, dir, fulFilledVdiBackups)
]) ])
@ -561,7 +562,7 @@ export default class {
// Remove xva file. // Remove xva file.
// Version 0.0.0 (Legacy) Delta Backup. // Version 0.0.0 (Legacy) Delta Backup.
handler.unlink(`${dir}/${getDeltaBackupNameWithoutExt(backup)}.xva`).catch(noop) handler.unlink(`${dir}/${getDeltaBackupNameWithoutExt(backup)}.xva`)::pCatch(noop)
}) })
) )
} }
@ -575,7 +576,7 @@ export default class {
await xapi.deleteVdi(oldBaseId) await xapi.deleteVdi(oldBaseId)
} }
}) })
).catch(noop) )::pCatch(noop)
// Returns relative path. // Returns relative path.
return `${dir}/${backupFormat}` return `${dir}/${backupFormat}`

View File

@ -20,7 +20,8 @@ import {
createRawObject, createRawObject,
forEach, forEach,
mapToArray, mapToArray,
noop noop,
pCatch
} from '../utils' } from '../utils'
// =================================================================== // ===================================================================
@ -89,16 +90,16 @@ export default class {
.then(tokens => { .then(tokens => {
forEach(tokens, token => { forEach(tokens, token => {
this._xo._tokens.remove(token.id) this._xo._tokens.remove(token.id)
.catch(noop) ::pCatch(noop)
}) })
}) })
.catch(noop) // Ignore any failures. ::pCatch(noop) // Ignore any failures.
// Remove the user from all its groups. // Remove the user from all its groups.
forEach(user.groups, groupId => { forEach(user.groups, groupId => {
this.getGroup(groupId) this.getGroup(groupId)
.then(group => this._removeUserFromGroup(id, group)) .then(group => this._removeUserFromGroup(id, group))
.catch(noop) // Ignore any failures. ::pCatch(noop) // Ignore any failures.
}) })
} }
@ -232,7 +233,7 @@ export default class {
forEach(group.users, userId => { forEach(group.users, userId => {
this.getUser(userId) this.getUser(userId)
.then(user => this._removeGroupFromUser(id, user)) .then(user => this._removeGroupFromUser(id, user))
.catch(noop) // Ignore any failures. ::pCatch(noop) // Ignore any failures.
}) })
} }

View File

@ -12,6 +12,7 @@ import {
isEmpty, isEmpty,
isString, isString,
noop, noop,
pCatch,
popProperty popProperty
} from '../utils' } from '../utils'
import { import {
@ -75,7 +76,7 @@ export default class {
} }
async unregisterXenServer (id) { async unregisterXenServer (id) {
this.disconnectXenServer(id).catch(noop) this.disconnectXenServer(id)::pCatch(noop)
if (!await this._servers.remove(id)) { // eslint-disable-line space-before-keywords if (!await this._servers.remove(id)) { // eslint-disable-line space-before-keywords
throw new NoSuchXenServer(id) throw new NoSuchXenServer(id)