lxc.local data in the catch() rather than then()
ryan-love opened this issue · 2 comments
I was messing around with the local method, using general linux command like whoami and ls but the data I wanted to display is being shown in the catch rather than the then method.
Here is a quick example of what i did.
router.get('/', function(req, res, next) {
lxc.local('ls').then((cmd) => {res.send("HELLO "+cmd)}).catch(e =>
console.log((res.send(e))))
});
ServerResponse { _events: [Object: null prototype] { finish: [ [Function: bound resOnFinish], [Function: onevent] ], end: [Function: onevent] }, _eventsCount: 2, _maxListeners: undefined, outputData: [], outputSize: 0, writable: true, _last: false, chunkedEncoding: false, shouldKeepAlive: true, useChunkedEncodingByDefault: true, sendDate: true, _removedConnection: false, _removedContLen: false, _removedTE: false, _contentLength: 75, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: Socket { connecting: false, _hadError: false, _parent: null, _host: null, _readableState: ReadableState { objectMode: false, highWaterMark: 16384, buffer: BufferList { head: null, tail: null, length: 0 }, length: 0, pipes: null, pipesCount: 0, flowing: true, ended: false, endEmitted: false, reading: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, resumeScheduled: false, paused: false, emitClose: false, autoDestroy: false, destroyed: false, defaultEncoding: 'utf8', awaitDrain: 0, readingMore: false, decoder: null, encoding: null }, readable: true, _events: [Object: null prototype] { end: [Array], timeout: [Function: socketOnTimeout], data: [Function: bound socketOnData], error: [Array], close: [Array], drain: [Function: bound socketOnDrain], resume: [Function: onSocketResume], pause: [Function: onSocketPause] }, _eventsCount: 8, _maxListeners: undefined, _writableState: WritableState { objectMode: false, highWaterMark: 16384, finalCalled: false, needDrain: false, ending: false, ended: false, finished: false, destroyed: false, decodeStrings: false, defaultEncoding: 'utf8', length: 0, writing: false, corked: 0, sync: false, bufferProcessing: false, onwrite: [Function: bound onwrite], writecb: null, writelen: 0, afterWriteTickInfo: [Object], bufferedRequest: null, lastBufferedRequest: null, pendingcb: 4, prefinished: false, errorEmitted: false, emitClose: false, autoDestroy: false, bufferedRequestCount: 0, corkedRequestsFree: [Object] }, writable: true, allowHalfOpen: true, _sockname: null, _pendingData: null, _pendingEncoding: '', server: Server { insecureHTTPParser: undefined, _events: [Object: null prototype], _eventsCount: 4, _maxListeners: undefined, _connections: 2, _handle: [TCP], _usingWorkers: false, _workers: [], _unref: false, allowHalfOpen: true, pauseOnConnect: false, httpAllowHalfOpen: false, timeout: 120000, keepAliveTimeout: 5000, maxHeadersCount: null, headersTimeout: 40000, _connectionKey: '6::::3000', [Symbol(IncomingMessage)]: [Function: IncomingMessage], [Symbol(ServerResponse)]: [Function: ServerResponse], [Symbol(asyncId)]: 4 }, _server: Server { insecureHTTPParser: undefined, _events: [Object: null prototype], _eventsCount: 4, _maxListeners: undefined, _connections: 2, _handle: [TCP], _usingWorkers: false, _workers: [], _unref: false, allowHalfOpen: true, pauseOnConnect: false, httpAllowHalfOpen: false, timeout: 120000, keepAliveTimeout: 5000, maxHeadersCount: null, headersTimeout: 40000, _connectionKey: '6::::3000', [Symbol(IncomingMessage)]: [Function: IncomingMessage], [Symbol(ServerResponse)]: [Function: ServerResponse], [Symbol(asyncId)]: 4 }, timeout: 120000, parser: HTTPParser { '0': [Function: parserOnHeaders], '1': [Function: parserOnHeadersComplete], '2': [Function: parserOnBody], '3': [Function: parserOnMessageComplete], '4': [Function: bound onParserExecute], _headers: [], _url: '', socket: [Circular], incoming: [IncomingMessage], outgoing: null, maxHeaderPairs: 2000, _consumed: true, onIncoming: [Function: bound parserOnIncoming], parsingHeadersStart: 0 }, on: [Function: socketListenerWrap], addListener: [Function: socketListenerWrap], prependListener: [Function: socketListenerWrap], _paused: false, _httpMessage: [Circular], _peername: { address: '::1', family: 'IPv6', port: 35428 }, [Symbol(asyncId)]: 7, [Symbol(kHandle)]: TCP { reading: true, onconnection: null, _consumed: true, [Symbol(owner)]: [Circular] }, [Symbol(lastWriteQueueSize)]: 0, [Symbol(timeout)]: Timeout { _idleTimeout: 120000, _idlePrev: [TimersList], _idleNext: [Timeout], _idleStart: 2788, _onTimeout: [Function: bound ], _timerArgs: undefined, _repeat: null, _destroyed: false, [Symbol(refed)]: false, [Symbol(asyncId)]: 8, [Symbol(triggerId)]: 7 }, [Symbol(kBuffer)]: null, [Symbol(kBufferCb)]: null, [Symbol(kBufferGen)]: null, [Symbol(kBytesRead)]: 0, [Symbol(kBytesWritten)]: 0 }, connection: Socket { connecting: false, _hadError: false, _parent: null, _host: null, _readableState: ReadableState { objectMode: false, highWaterMark: 16384, buffer: BufferList { head: null, tail: null, length: 0 }, length: 0, pipes: null, pipesCount: 0, flowing: true, ended: false, endEmitted: false, reading: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, resumeScheduled: false, paused: false, emitClose: false, autoDestroy: false, destroyed: false, defaultEncoding: 'utf8', awaitDrain: 0, readingMore: false, decoder: null, encoding: null }, readable: true, _events: [Object: null prototype] { end: [Array], timeout: [Function: socketOnTimeout], data: [Function: bound socketOnData], error: [Array], close: [Array], drain: [Function: bound socketOnDrain], resume: [Function: onSocketResume], pause: [Function: onSocketPause] }, _eventsCount: 8, _maxListeners: undefined, _writableState: WritableState { objectMode: false, highWaterMark: 16384, finalCalled: false, needDrain: false, ending: false, ended: false, finished: false, destroyed: false, decodeStrings: false, defaultEncoding: 'utf8', length: 0, writing: false, corked: 0, sync: false, bufferProcessing: false, onwrite: [Function: bound onwrite], writecb: null, writelen: 0, afterWriteTickInfo: [Object], bufferedRequest: null, lastBufferedRequest: null, pendingcb: 4, prefinished: false, errorEmitted: false, emitClose: false, autoDestroy: false, bufferedRequestCount: 0, corkedRequestsFree: [Object] }, writable: true, allowHalfOpen: true, _sockname: null, _pendingData: null, _pendingEncoding: '', server: Server { insecureHTTPParser: undefined, _events: [Object: null prototype], _eventsCount: 4, _maxListeners: undefined, _connections: 2, _handle: [TCP], _usingWorkers: false, _workers: [], _unref: false, allowHalfOpen: true, pauseOnConnect: false, httpAllowHalfOpen: false, timeout: 120000, keepAliveTimeout: 5000, maxHeadersCount: null, headersTimeout: 40000, _connectionKey: '6::::3000', [Symbol(IncomingMessage)]: [Function: IncomingMessage], [Symbol(ServerResponse)]: [Function: ServerResponse], [Symbol(asyncId)]: 4 }, _server: Server { insecureHTTPParser: undefined, _events: [Object: null prototype], _eventsCount: 4, _maxListeners: undefined, _connections: 2, _handle: [TCP], _usingWorkers: false, _workers: [], _unref: false, allowHalfOpen: true, pauseOnConnect: false, httpAllowHalfOpen: false, timeout: 120000, keepAliveTimeout: 5000, maxHeadersCount: null, headersTimeout: 40000, _connectionKey: '6::::3000', [Symbol(IncomingMessage)]: [Function: IncomingMessage], [Symbol(ServerResponse)]: [Function: ServerResponse], [Symbol(asyncId)]: 4 }, timeout: 120000, parser: HTTPParser { '0': [Function: parserOnHeaders], '1': [Function: parserOnHeadersComplete], '2': [Function: parserOnBody], '3': [Function: parserOnMessageComplete], '4': [Function: bound onParserExecute], _headers: [], _url: '', socket: [Circular], incoming: [IncomingMessage], outgoing: null, maxHeaderPairs: 2000, _consumed: true, onIncoming: [Function: bound parserOnIncoming], parsingHeadersStart: 0 }, on: [Function: socketListenerWrap], addListener: [Function: socketListenerWrap], prependListener: [Function: socketListenerWrap], _paused: false, _httpMessage: [Circular], _peername: { address: '::1', family: 'IPv6', port: 35428 }, [Symbol(asyncId)]: 7, [Symbol(kHandle)]: TCP { reading: true, onconnection: null, _consumed: true, [Symbol(owner)]: [Circular] }, [Symbol(lastWriteQueueSize)]: 0, [Symbol(timeout)]: Timeout { _idleTimeout: 120000, _idlePrev: [TimersList], _idleNext: [Timeout], _idleStart: 2788, _onTimeout: [Function: bound ], _timerArgs: undefined, _repeat: null, _destroyed: false, [Symbol(refed)]: false, [Symbol(asyncId)]: 8, [Symbol(triggerId)]: 7 }, [Symbol(kBuffer)]: null, [Symbol(kBufferCb)]: null, [Symbol(kBufferGen)]: null, [Symbol(kBytesRead)]: 0, [Symbol(kBytesWritten)]: 0 }, _header: 'HTTP/1.1 200 OK\r\n' + 'X-Powered-By: Express\r\n' + 'Content-Type: text/html; charset=utf-8\r\n' + 'Content-Length: 75\r\n' + 'ETag: W/"4b-nELqJLKPOr77j68rMnKt52k9OLo"\r\n' + 'Date: Tue, 14 Apr 2020 10:21:07 GMT\r\n' + 'Connection: keep-alive\r\n' + '\r\n', _onPendingData: [Function: bound updateOutgoingData], _sent100: false, _expect_continue: false, req: IncomingMessage { _readableState: ReadableState { objectMode: false, highWaterMark: 16384, buffer: BufferList { head: null, tail: null, length: 0 }, length: 0, pipes: null, pipesCount: 0, flowing: null, ended: true, endEmitted: false, reading: false, sync: true, needReadable: false, emittedReadable: false, readableListening: false, resumeScheduled: false, paused: true, emitClose: true, autoDestroy: false, destroyed: false, defaultEncoding: 'utf8', awaitDrain: 0, readingMore: true, decoder: null, encoding: null }, readable: true, _events: [Object: null prototype] { end: [Function: resetHeadersTimeoutOnReqEnd] }, _eventsCount: 1, _maxListeners: undefined, socket: Socket { connecting: false, _hadError: false, _parent: null, _host: null, _readableState: [ReadableState], readable: true, _events: [Object: null prototype], _eventsCount: 8, _maxListeners: undefined, _writableState: [WritableState], writable: true, allowHalfOpen: true, _sockname: null, _pendingData: null, _pendingEncoding: '', server: [Server], _server: [Server], timeout: 120000, parser: [HTTPParser], on: [Function: socketListenerWrap], addListener: [Function: socketListenerWrap], prependListener: [Function: socketListenerWrap], _paused: false, _httpMessage: [Circular], _peername: [Object], [Symbol(asyncId)]: 7, [Symbol(kHandle)]: [TCP], [Symbol(lastWriteQueueSize)]: 0, [Symbol(timeout)]: Timeout { _idleTimeout: 120000, _idlePrev: [TimersList], _idleNext: [Timeout], _idleStart: 2788, _onTimeout: [Function: bound ], _timerArgs: undefined, _repeat: null, _destroyed: false, [Symbol(refed)]: false, [Symbol(asyncId)]: 8, [Symbol(triggerId)]: 7 }, [Symbol(kBuffer)]: null, [Symbol(kBufferCb)]: null, [Symbol(kBufferGen)]: null, [Symbol(kBytesRead)]: 0, [Symbol(kBytesWritten)]: 0 }, connection: Socket { connecting: false, _hadError: false, _parent: null, _host: null, _readableState: [ReadableState], readable: true, _events: [Object: null prototype], _eventsCount: 8, _maxListeners: undefined, _writableState: [WritableState], writable: true, allowHalfOpen: true, _sockname: null, _pendingData: null, _pendingEncoding: '', server: [Server], _server: [Server], timeout: 120000, parser: [HTTPParser], on: [Function: socketListenerWrap], addListener: [Function: socketListenerWrap], prependListener: [Function: socketListenerWrap], _paused: false, _httpMessage: [Circular], _peername: [Object], [Symbol(asyncId)]: 7, [Symbol(kHandle)]: [TCP], [Symbol(lastWriteQueueSize)]: 0, [Symbol(timeout)]: Timeout { _idleTimeout: 120000, _idlePrev: [TimersList], _idleNext: [Timeout], _idleStart: 2788, _onTimeout: [Function: bound ], _timerArgs: undefined, _repeat: null, _destroyed: false, [Symbol(refed)]: false, [Symbol(asyncId)]: 8, [Symbol(triggerId)]: 7 }, [Symbol(kBuffer)]: null, [Symbol(kBufferCb)]: null, [Symbol(kBufferGen)]: null, [Symbol(kBytesRead)]: 0, [Symbol(kBytesWritten)]: 0 }, httpVersionMajor: 1, httpVersionMinor: 1, httpVersion: '1.1', complete: true, headers: { host: 'localhost:3000', connection: 'keep-alive', 'cache-control': 'max-age=0', 'upgrade-insecure-requests': '1', 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36', 'sec-fetch-dest': 'document', accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'sec-fetch-site': 'none', 'sec-fetch-mode': 'navigate', 'sec-fetch-user': '?1', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'en-US,en-GB;q=0.9,en;q=0.8', 'if-none-match': 'W/"1-TcfJ7ENO0GUCdnE2eJdj7BHSxLc"' }, rawHeaders: [ 'Host', 'localhost:3000', 'Connection', 'keep-alive', 'Cache-Control', 'max-age=0', 'Upgrade-Insecure-Requests', '1', 'User-Agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36', 'Sec-Fetch-Dest', 'document', 'Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'Sec-Fetch-Site', 'none', 'Sec-Fetch-Mode', 'navigate', 'Sec-Fetch-User', '?1', 'Accept-Encoding', 'gzip, deflate, br', 'Accept-Language', 'en-US,en-GB;q=0.9,en;q=0.8', 'If-None-Match', 'W/"1-TcfJ7ENO0GUCdnE2eJdj7BHSxLc"' ], trailers: {}, rawTrailers: [], aborted: false, upgrade: false, url: '/', method: 'GET', statusCode: null, statusMessage: null, client: Socket { connecting: false, _hadError: false, _parent: null, _host: null, _readableState: [ReadableState], readable: true, _events: [Object: null prototype], _eventsCount: 8, _maxListeners: undefined, _writableState: [WritableState], writable: true, allowHalfOpen: true, _sockname: null, _pendingData: null, _pendingEncoding: '', server: [Server], _server: [Server], timeout: 120000, parser: [HTTPParser], on: [Function: socketListenerWrap], addListener: [Function: socketListenerWrap], prependListener: [Function: socketListenerWrap], _paused: false, _httpMessage: [Circular], _peername: [Object], [Symbol(asyncId)]: 7, [Symbol(kHandle)]: [TCP], [Symbol(lastWriteQueueSize)]: 0, [Symbol(timeout)]: Timeout { _idleTimeout: 120000, _idlePrev: [TimersList], _idleNext: [Timeout], _idleStart: 2788, _onTimeout: [Function: bound ], _timerArgs: undefined, _repeat: null, _destroyed: false, [Symbol(refed)]: false, [Symbol(asyncId)]: 8, [Symbol(triggerId)]: 7 }, [Symbol(kBuffer)]: null, [Symbol(kBufferCb)]: null, [Symbol(kBufferGen)]: null, [Symbol(kBytesRead)]: 0, [Symbol(kBytesWritten)]: 0 }, _consuming: false, _dumped: false, next: [Function: next], baseUrl: '', originalUrl: '/', _parsedUrl: Url { protocol: null, slashes: null, auth: null, host: null, port: null, hostname: null, hash: null, search: null, query: null, pathname: '/', path: '/', href: '/', _raw: '/' }, params: {}, query: {}, res: [Circular], _startAt: [ 2867, 735891581 ], _startTime: 2020-04-14T10:21:07.344Z, _remoteAddress: '::1', body: {}, secret: undefined, cookies: [Object: null prototype] {}, signedCookies: [Object: null prototype] {}, _parsedOriginalUrl: Url { protocol: null, slashes: null, auth: null, host: null, port: null, hostname: null, hash: null, search: null, query: null, pathname: '/', path: '/', href: '/', _raw: '/' }, route: Route { path: '/', stack: [Array], methods: [Object] } }, locals: [Object: null prototype] {}, _startAt: [ 2867, 746746873 ], _startTime: 2020-04-14T10:21:07.355Z, writeHead: [Function: writeHead], __onFinished: [Function: listener] { queue: [ [Function: logRequest] ] }, statusCode: 200, statusMessage: 'OK', [Symbol(kNeedDrain)]: false, [Symbol(isCorked)]: false, [Symbol(kOutHeaders)]: [Object: null prototype] { 'x-powered-by': [ 'X-Powered-By', 'Express' ], 'content-type': [ 'Content-Type', 'text/html; charset=utf-8' ], 'content-length': [ 'Content-Length', '75' ], etag: [ 'ETag', 'W/"4b-nELqJLKPOr77j68rMnKt52k9OLo"' ] } } GET / 200 10.855 ms - 75
If you need more information, just ask.
Thank you for your interest in the package and for pointing out the bug.
Fixed in 1.0.13
sidenote, this would have worked also:
lxc.local('ls', {}, false)
is not documented though, my bad