chore: replace ::pCatch(noop) with ::ignoreErrors()

This commit is contained in:
Julien Fontanet 2017-06-27 15:00:37 +02:00
parent e3f1545cdb
commit cfc6374995
10 changed files with 85 additions and 97 deletions

View File

@ -1,14 +1,10 @@
import {
noop,
pCatch
} from '../utils'
import { ignoreErrors } from 'promise-toolbox'
export async function add ({autoConnect = true, ...props}) {
const server = await this.registerXenServer(props)
if (autoConnect) {
// Connect asynchronously, ignore any errors.
this.connectXenServer(server.id)::pCatch(noop)
this.connectXenServer(server.id)::ignoreErrors()
}
return server.id
@ -109,7 +105,7 @@ set.params = {
// -------------------------------------------------------------------
export async function connect ({id}) {
this.updateXenServer(id, {enabled: true})::pCatch(noop)
this.updateXenServer(id, {enabled: true})::ignoreErrors()
await this.connectXenServer(id)
}
@ -126,7 +122,7 @@ connect.params = {
// -------------------------------------------------------------------
export async function disconnect ({id}) {
this.updateXenServer(id, {enabled: false})::pCatch(noop)
this.updateXenServer(id, {enabled: false})::ignoreErrors()
await this.disconnectXenServer(id)
}

View File

@ -1,8 +1,6 @@
import {
diffItems,
noop,
pCatch
} from '../utils'
import { ignoreErrors } from 'promise-toolbox'
import { diffItems } from '../utils'
// ===================================================================
@ -12,7 +10,7 @@ async function delete_ ({vif}) {
vif.id,
null,
vif.allowedIpv4Addresses.concat(vif.allowedIpv6Addresses)
)::pCatch(noop)
)::ignoreErrors()
await this.getXapi(vif).deleteVif(vif._xapiId)
}

View File

@ -12,12 +12,13 @@ sortBy = require 'lodash/sortBy'
startsWith = require 'lodash/startsWith'
{coroutine: $coroutine} = require 'bluebird'
{format} = require 'json-rpc-peer'
{ ignoreErrors } = require('promise-toolbox')
{
forbiddenOperation,
invalidParameters,
unauthorized
} = require('xo-common/api-errors')
{
forEach,
formatXml: $js2xml,
@ -25,10 +26,8 @@ startsWith = require 'lodash/startsWith'
map,
mapFilter,
mapToArray,
noop,
parseSize,
parseXml,
pCatch,
pFinally
} = require '../utils'
{isVmRunning: $isVmRunning} = require('../xapi')
@ -174,7 +173,7 @@ create = $coroutine (params) ->
)
if params.bootAfterCreate
pCatch.call(xapi.startVm(vm._xapiId), noop)
ignoreErrors.call(xapi.startVm(vm._xapiId))
return vm.id
@ -324,9 +323,8 @@ delete_ = $coroutine ({vm, delete_disks: deleteDisks = false }) ->
@getAllAcls().then((acls) =>
Promise.all(mapFilter(acls, (acl) =>
if (acl.object == vm.id)
return pCatch.call(
@removeAcl(acl.subject, acl.object, acl.action),
noop
return ignoreErrors.call(
@removeAcl(acl.subject, acl.object, acl.action)
)
))
)
@ -334,13 +332,12 @@ delete_ = $coroutine ({vm, delete_disks: deleteDisks = false }) ->
# Update IP pools
yield Promise.all(map(vm.VIFs, (vifId) =>
vif = xapi.getObject(vifId)
return pCatch.call(
return ignoreErrors.call(
this.allocIpAddresses(
vifId,
null,
concat(vif.ipv4_allowed, vif.ipv6_allowed)
),
noop
)
)
))
@ -364,12 +361,11 @@ delete_ = $coroutine ({vm, delete_disks: deleteDisks = false }) ->
resourceSetUsage = @computeVmResourcesUsage(vm)
ipPoolsUsage = yield @computeVmIpPoolsUsage(vm)
pCatch.call(
ignoreErrors.call(
@releaseLimitsInResourceSet(
merge(resourceSetUsage, ipPoolsUsage),
resourceSet
),
noop
)
)
return xapi.deleteVm(vm._xapiId, deleteDisks)
@ -1172,7 +1168,7 @@ createInterface = $coroutine ({
{ push } = ipAddresses = []
push.apply(ipAddresses, allowedIpv4Addresses) if allowedIpv4Addresses
push.apply(ipAddresses, allowedIpv6Addresses) if allowedIpv6Addresses
pCatch.call(@allocIpAddresses(vif.$id, allo), noop) if ipAddresses.length
ignoreErrors.call(@allocIpAddresses(vif.$id, allo)) if ipAddresses.length
return vif.$id

View File

@ -1,5 +1,6 @@
import eventToPromise from 'event-to-promise'
import through2 from 'through2'
import { ignoreErrors } from 'promise-toolbox'
import {
parse
@ -8,8 +9,6 @@ import {
import {
addChecksumToReadStream,
getPseudoRandomBytes,
noop,
pCatch,
streamToBuffer,
validChecksumOfReadStream
} from '../utils'
@ -70,7 +69,7 @@ export default class RemoteHandlerAbstract {
error: error.message || String(error)
}
} finally {
this.unlink(testFileName).catch(noop)
this.unlink(testFileName)::ignoreErrors()
}
}
@ -127,9 +126,12 @@ export default class RemoteHandlerAbstract {
options.end === undefined &&
options.start === undefined
) {
promise = Promise.all([ promise, this.getSize(file).then(size => {
stream.length = size
}, noop) ])
promise = Promise.all([
promise,
this.getSize(file).then(size => {
stream.length = size
})::ignoreErrors()
])
}
return promise.then(() => stream)
@ -140,7 +142,7 @@ export default class RemoteHandlerAbstract {
}
// avoid a unhandled rejection warning
streamP.catch(noop)
streamP::ignoreErrors()
return this.readFile(`${file}.checksum`).then(
checksum => streamP.then(stream => {
@ -206,7 +208,7 @@ export default class RemoteHandlerAbstract {
checksum = true
} = {}) {
if (checksum) {
this._unlink(`${file}.checksum`)::pCatch(noop)
this._unlink(`${file}.checksum`)::ignoreErrors()
}
return this._unlink(file)

View File

@ -4,7 +4,7 @@ import fatfs from 'fatfs'
import synchronized from 'decorator-synchronized'
import tarStream from 'tar-stream'
import vmdkToVhd from 'xo-vmdk-to-vhd'
import { cancellable, defer } from 'promise-toolbox'
import { cancellable, defer, ignoreErrors } from 'promise-toolbox'
import { PassThrough } from 'stream'
import { forbiddenOperation } from 'xo-common/api-errors'
import {
@ -37,7 +37,6 @@ import {
isFunction,
map,
mapToArray,
noop,
pAll,
pCatch,
pDelay,
@ -237,7 +236,7 @@ export default class Xapi extends XapiBase {
if (value != null) {
return this.call(`${namespace}.set_${camelToSnakeCase(name)}`, ref, prepareXapiParam(value))
}
}))::pCatch(noop)
}))::ignoreErrors()
}
async _updateObjectMapProperty (object, prop, values) {
@ -259,7 +258,7 @@ export default class Xapi extends XapiBase {
return value === null
? removal
: removal::pCatch(noop).then(() => this.call(add, ref, name, prepareXapiParam(value)))
: removal::ignoreErrors().then(() => this.call(add, ref, name, prepareXapiParam(value)))
}
}))
}
@ -672,14 +671,14 @@ export default class Xapi extends XapiBase {
vdi.VBDs.length < 2 ||
every(vdi.$VBDs, vbd => vbd.VM === vm.$ref)
) {
return this._deleteVdi(vdi)::pCatch(noop)
return this._deleteVdi(vdi)::ignoreErrors()
}
console.error(`cannot delete VDI ${vdi.name_label} (from VM ${vm.name_label})`)
}))
}
await Promise.all(mapToArray(vm.$snapshots, snapshot =>
this.deleteVm(snapshot.$id)::pCatch(noop)
this.deleteVm(snapshot.$id)::ignoreErrors()
))
await this.call('VM.destroy', vm.$ref)
@ -729,7 +728,7 @@ export default class Xapi extends XapiBase {
if (snapshotRef !== undefined) {
promise.then(_ => _.task::pFinally(() =>
this.deleteVm(snapshotRef)::pCatch(noop)
this.deleteVm(snapshotRef)::ignoreErrors()
))
}
@ -785,7 +784,7 @@ export default class Xapi extends XapiBase {
if (snapshotNameLabel) {
this._setObjectProperties(vm, {
nameLabel: snapshotNameLabel
})::pCatch(noop)
})::ignoreErrors()
}
const baseVm = baseVmId && this.getObject(baseVmId)
@ -823,7 +822,7 @@ export default class Xapi extends XapiBase {
//
// The snapshot must not exist otherwise it could break the
// next export.
this._deleteVdi(vdi)::pCatch(noop)
this._deleteVdi(vdi)::ignoreErrors()
return
}
@ -945,7 +944,7 @@ export default class Xapi extends XapiBase {
// 2. Delete all VBDs which may have been created by the import.
await Promise.all(mapToArray(
vm.$VBDs,
vbd => this._deleteVbd(vbd)::pCatch(noop)
vbd => this._deleteVbd(vbd)::ignoreErrors()
))
// 3. Create VDIs.
@ -1033,7 +1032,7 @@ export default class Xapi extends XapiBase {
])
if (deleteBase && baseVm) {
this._deleteVm(baseVm)::pCatch(noop)
this._deleteVm(baseVm)::ignoreErrors()
}
await Promise.all([
@ -1189,7 +1188,7 @@ export default class Xapi extends XapiBase {
if (onVmCreation) {
this._waitObject(
obj => obj && obj.current_operations && taskRef in obj.current_operations
).then(onVmCreation)::pCatch(noop)
).then(onVmCreation)::ignoreErrors()
}
const vmRef = await this.putResource(
@ -1367,7 +1366,7 @@ export default class Xapi extends XapiBase {
let ref
try {
ref = await this.call('VM.snapshot_with_quiesce', vm.$ref, nameLabel)
this.addTag(ref, 'quiesce')::pCatch(noop) // ignore any failures
this.addTag(ref, 'quiesce')::ignoreErrors()
await this._waitObjectState(ref, vm => includes(vm.tags, 'quiesce'))
} catch (error) {
@ -1497,10 +1496,10 @@ export default class Xapi extends XapiBase {
} finally {
this._setObjectProperties(vm, {
PV_bootloader: bootloader
})::pCatch(noop)
})::ignoreErrors()
forEach(bootables, ([ vbd, bootable ]) => {
this._setObjectProperties(vbd, { bootable })::pCatch(noop)
this._setObjectProperties(vbd, { bootable })::ignoreErrors()
})
}
}
@ -1701,7 +1700,7 @@ export default class Xapi extends XapiBase {
throw error
}
await this.call('VBD.eject', cdDrive.$ref)::pCatch(noop)
await this.call('VBD.eject', cdDrive.$ref)::ignoreErrors()
// Retry.
await this.call('VBD.insert', cdDrive.$ref, cd.$ref)
@ -1747,7 +1746,7 @@ export default class Xapi extends XapiBase {
}
async _deleteVbd (vbd) {
await this._disconnectVbd(vbd)::pCatch(noop)
await this._disconnectVbd(vbd)::ignoreErrors()
await this.call('VBD.destroy', vbd.$ref)
}
@ -1759,7 +1758,7 @@ export default class Xapi extends XapiBase {
async destroyVbdsFromVm (vmId) {
await Promise.all(
mapToArray(this.getObject(vmId).$VBDs, async vbd => {
await this.disconnectVbd(vbd.$ref)::pCatch(noop)
await this.disconnectVbd(vbd.$ref)::ignoreErrors()
return this.call('VBD.destroy', vbd.$ref)
})
)
@ -1978,7 +1977,7 @@ export default class Xapi extends XapiBase {
const newPifs = await this.call('pool.create_VLAN_from_PIF', physPif.$ref, pif.network, asInteger(vlan))
await Promise.all(
mapToArray(newPifs, pifRef =>
!wasAttached[this.getObject(pifRef).host] && this.call('PIF.unplug', pifRef)::pCatch(noop)
!wasAttached[this.getObject(pifRef).host] && this.call('PIF.unplug', pifRef)::ignoreErrors()
)
)
}

View File

@ -1,16 +1,17 @@
import deferrable from 'golike-defer'
import find from 'lodash/find'
import gte from 'lodash/gte'
import includes from 'lodash/includes'
import isEmpty from 'lodash/isEmpty'
import lte from 'lodash/lte'
import { ignoreErrors } from 'promise-toolbox'
import {
find,
gte,
includes,
isEmpty,
lte
} from 'lodash'
import {
forEach,
mapToArray,
noop,
parseSize,
pCatch
parseSize
} from '../../utils'
import {
@ -64,7 +65,7 @@ export default {
// Removes disks from the provision XML, we will create them by
// ourselves.
await this.call('VM.remove_from_other_config', vmRef, 'disks')::pCatch(noop)
await this.call('VM.remove_from_other_config', vmRef, 'disks')::ignoreErrors()
// Creates the VDIs and executes the initial steps of the
// installation.
@ -386,9 +387,9 @@ export default {
if (snapshot.snapshot_info['power-state-at-snapshot'] === 'Running') {
const vm = snapshot.$snapshot_of
if (vm.power_state === 'Halted') {
this.startVm(vm.$id)::pCatch(noop)
this.startVm(vm.$id)::ignoreErrors()
} else if (vm.power_state === 'Suspended') {
this.resumeVm(vm.$id)::pCatch(noop)
this.resumeVm(vm.$id)::ignoreErrors()
}
}
},

View File

@ -1,11 +1,11 @@
import Token, { Tokens } from '../models/token'
import { noSuchObject } from 'xo-common/api-errors'
import { ignoreErrors } from 'promise-toolbox'
import Token, { Tokens } from '../models/token'
import {
createRawObject,
forEach,
generateToken,
pCatch,
noop
generateToken
} from '../utils'
// ===================================================================
@ -180,7 +180,7 @@ export default class {
if (!(
token.expiration > Date.now()
)) {
this._tokens.remove(id)::pCatch(noop)
this._tokens.remove(id)::ignoreErrors()
throw noSuchAuthenticationToken(id)
}

View File

@ -3,7 +3,7 @@ import escapeStringRegexp from 'escape-string-regexp'
import eventToPromise from 'event-to-promise'
import execa from 'execa'
import splitLines from 'split-lines'
import { CancelToken } from 'promise-toolbox'
import { CancelToken, ignoreErrors } from 'promise-toolbox'
import { createParser as createPairsParser } from 'parse-pairs'
import { createReadStream, readdir, stat } from 'fs'
import { satisfies as versionSatisfies } from 'semver'
@ -35,7 +35,6 @@ import {
mapFilter,
mapToArray,
noop,
pCatch,
pFinally,
pFromCallback,
pSettle,
@ -445,7 +444,7 @@ export default class {
// Once done, (asynchronously) remove the (now obsolete) local
// base.
if (localBaseUuid) {
promise.then(() => srcXapi.deleteVm(localBaseUuid))::pCatch(noop)
promise.then(() => srcXapi.deleteVm(localBaseUuid))::ignoreErrors()
}
// (Asynchronously) Identify snapshot as future base.
@ -453,7 +452,7 @@ export default class {
return srcXapi._updateObjectMapProperty(srcVm, 'other_config', {
[TAG_LAST_BASE_DELTA]: delta.vm.uuid
})
})::pCatch(noop)
})::ignoreErrors()
return promise
})()
@ -683,7 +682,7 @@ export default class {
filter(vdiParent.$snapshots, { name_label: 'XO_DELTA_BASE_VDI_SNAPSHOT' }),
base => base.snapshot_time
)
forEach(bases, base => { xapi.deleteVdi(base.$id)::pCatch(noop) })
forEach(bases, base => { xapi.deleteVdi(base.$id)::ignoreErrors() })
// Export full or delta backup.
const vdiFilename = `${date}_${isFull ? 'full' : 'delta'}.vhd`
@ -713,7 +712,7 @@ export default class {
])
} catch (error) {
// Remove new backup. (corrupt).
await handler.unlink(backupFullPath)::pCatch(noop)
await handler.unlink(backupFullPath)::ignoreErrors()
throw error
}
@ -736,7 +735,7 @@ export default class {
// Remove xva file.
// Version 0.0.0 (Legacy) Delta Backup.
handler.unlink(`${dir}/${getDeltaBackupNameWithoutExt(backup)}.xva`)::pCatch(noop)
handler.unlink(`${dir}/${getDeltaBackupNameWithoutExt(backup)}.xva`)::ignoreErrors()
]))
}
}
@ -754,7 +753,7 @@ export default class {
base => base.snapshot_time
)
const baseVm = bases.pop()
forEach(bases, base => { xapi.deleteVm(base.$id)::pCatch(noop) })
forEach(bases, base => { xapi.deleteVm(base.$id)::ignoreErrors() })
// Check backup dirs.
const dir = `vm_delta_${tag}_${vm.uuid}`
@ -824,7 +823,7 @@ export default class {
}
$onFailure(() => asyncMap(fulFilledVdiBackups, vdiBackup =>
handler.unlink(`${dir}/${vdiBackup.value()}`)::pCatch(noop)
handler.unlink(`${dir}/${vdiBackup.value()}`)::ignoreErrors()
))
if (error) {
@ -859,7 +858,7 @@ export default class {
await this._removeOldDeltaVmBackups(xapi, { vm, handler, dir, retention })
if (baseVm) {
xapi.deleteVm(baseVm.$id)::pCatch(noop)
xapi.deleteVm(baseVm.$id)::ignoreErrors()
}
return {
@ -984,7 +983,7 @@ export default class {
_removeVms (xapi, vms) {
return Promise.all(mapToArray(vms, vm =>
// Do not consider a failure to delete an old copy as a fatal error.
xapi.deleteVm(vm.$id)::pCatch(noop)
xapi.deleteVm(vm.$id)::ignoreErrors()
))
}
@ -1124,7 +1123,7 @@ export default class {
const entriesMap = {}
await Promise.all(mapToArray(entries, async name => {
const stats = await pFromCallback(cb => stat(`${path}/${name}`, cb))::pCatch(noop)
const stats = await pFromCallback(cb => stat(`${path}/${name}`, cb))::ignoreErrors()
if (stats) {
entriesMap[stats.isDirectory() ? `${name}/` : name] = {}
}

View File

@ -1,5 +1,5 @@
import filter from 'lodash/filter'
import includes from 'lodash/includes'
import { filter, includes } from 'lodash'
import { ignoreErrors } from 'promise-toolbox'
import {
hash,
needsRehash,
@ -20,9 +20,7 @@ import {
forEach,
isEmpty,
lightSet,
mapToArray,
noop,
pCatch
mapToArray
} from '../utils'
// ===================================================================
@ -106,15 +104,15 @@ export default class {
this._xo.getAuthenticationTokensForUser(id)
.then(tokens => {
forEach(tokens, token => {
this._xo.deleteAuthenticationToken(id)::pCatch(noop)
this._xo.deleteAuthenticationToken(id)::ignoreErrors()
})
})
::pCatch(noop) // Ignore any failures.
::ignoreErrors()
// Remove ACLs for this user.
this._xo.getAclsForSubject(id).then(acls => {
forEach(acls, acl => {
this._xo.removeAcl(id, acl.object, acl.action)::pCatch(noop)
this._xo.removeAcl(id, acl.object, acl.action)::ignoreErrors()
})
})
@ -122,7 +120,7 @@ export default class {
forEach(user.groups, groupId => {
this.getGroup(groupId)
.then(group => this._removeUserFromGroup(id, group))
::pCatch(noop) // Ignore any failures.
::ignoreErrors()
})
}
@ -268,7 +266,7 @@ export default class {
// Remove ACLs for this group.
this._xo.getAclsForSubject(id).then(acls => {
forEach(acls, acl => {
this._xo.removeAcl(id, acl.object, acl.action)::pCatch(noop)
this._xo.removeAcl(id, acl.object, acl.action)::ignoreErrors()
})
})
@ -276,7 +274,7 @@ export default class {
forEach(group.users, userId => {
this.getUser(userId)
.then(user => this._removeGroupFromUser(id, user))
::pCatch(noop) // Ignore any failures.
::ignoreErrors()
})
}

View File

@ -1,3 +1,4 @@
import { ignoreErrors } from 'promise-toolbox'
import { noSuchObject } from 'xo-common/api-errors'
import Xapi from '../xapi'
@ -9,8 +10,6 @@ import {
forEach,
isEmpty,
isString,
noop,
pCatch,
popProperty,
serializeError
} from '../utils'
@ -81,7 +80,7 @@ export default class {
}
async unregisterXenServer (id) {
this.disconnectXenServer(id)::pCatch(noop)
this.disconnectXenServer(id)::ignoreErrors()
if (!await this._servers.remove(id)) {
throw noSuchObject(id, 'xenServer')