fix file delete (unlink) so catches error uses promise

This commit is contained in:
David Kebler 2018-05-27 13:05:38 -07:00
parent 949bd5b3b1
commit 36d1cf629f
3 changed files with 17 additions and 12 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@uci/socket",
"version": "0.1.3",
"version": "0.1.4",
"description": "JSON packet intra(named)/inter(TCP) host communication over socket",
"main": "src",
"scripts": {
@ -38,17 +38,17 @@
"devDependencies": {
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"codecov": "^3.0.0",
"esm": "^3.0.21",
"codecov": "^3.0.2",
"esm": "^3.0.37",
"istanbul": "^0.4.5",
"mocha": "^5.0.1",
"nodemon": "^1.15.1"
"mocha": "^5.2.0",
"nodemon": "^1.17.5"
},
"dependencies": {
"@uci/logger": "^0.0.2",
"@uci/logger": "0.0.3",
"better-try-catch": "^0.6.2",
"clone": "^2.1.1",
"death": "^1.1.0",
"make-dir": "^1.2.0"
"make-dir": "^1.3.0"
}
}

View file

@ -105,7 +105,7 @@ export default class Consumer extends Socket {
let res = await this._packetProcess(reply)
if (!res) { // if process was not promise returning like just logged to console
res = reply
log.warn('consumer function was not promise returning - resolving unprocessed')
log.warn('consumer function was not promise returning further processing may be out of sequence')
}
resolve(res)
}) //end listener
@ -143,7 +143,7 @@ export default class Consumer extends Socket {
// TODO do some extra security here?
let res = await this._packetProcess(packet)
if (!res) { // if process was not promise returning like just logged to console
log.warn('consumer function was not promise returning - resolving unprocessed')
log.warn('consumer function was not promise returning')
}
})
// listen on socket stream

View file

@ -1,5 +1,6 @@
import { Server } from 'net'
import { unlink as fileDelete } from 'fs'
import { promisify } from 'util'
import path from 'path'
import mkdir from 'make-dir'
import btc from 'better-try-catch'
@ -52,9 +53,13 @@ export default class Socket extends Server {
// recover from socket file that was not removed
if (err.code === 'EADDRINUSE') {
if (this.opts.path) { // if TCP socket should already be dead
log.warn({socket: this.opts.path}, 'socket already exists...deleting')
await fileDelete(this.opts.path)
return await this._listen(this.opts)
let [err, res] = log.info(await btc(promisify(fileDelete))(this.opts.path))
if(!err) {
log.info({res:res, socket: this.opts.path}, 'socket already exists.....deleted')
return await this._listen(this.opts)
}
log.fatal({err:err},'error deleting socket. Can not establish a socket')
return err
}
}
if (err.code ==='EACCES'){