diff --git a/packages/basics/src/file-save.js b/packages/basics/src/file-save.js index d16c35805..beacf6378 100644 --- a/packages/basics/src/file-save.js +++ b/packages/basics/src/file-save.js @@ -65,11 +65,11 @@ export default function FILESave(data, feed) { this.whenFinish = new Promise((resolve, reject) => { const output = compress ? this.input.pipe(createWriteStream(filename)) : this.input; output.once('error', (err) => { - debug('ezs')(`WARNING: ${filename} not saved. ${err}`); + debug('ezs:warn')(`File ${filename} not saved.`, this.ezs.serializeError(err)); reject(err); }); output.once('close', () => { - debug('ezs')(`${filename} saved.`); + debug('ezs:info')(`${filename} saved.`); lstat(filename, (err, stat) => { if (err) { return reject(err); diff --git a/packages/basics/src/tar-extract.js b/packages/basics/src/tar-extract.js index 345885394..2b2a7a57d 100644 --- a/packages/basics/src/tar-extract.js +++ b/packages/basics/src/tar-extract.js @@ -3,6 +3,7 @@ import micromatch from 'micromatch'; import { createGunzip } from 'zlib'; import getStream from 'get-stream'; import writeTo from 'stream-write'; +import debug from 'debug'; /** * Take the content of a tar file, extract some files. @@ -61,7 +62,7 @@ export default function TARExtract(data, feed) { () => next(), ); } catch (e) { - console.warn(`WARNING: file was ignored (${header.name})`, e); + debug('ezs:warn')(`File was ignored (${header.name})`, ezs.serializeError(e)); stream.resume(); return next(); } diff --git a/packages/basics/src/url-connect.js b/packages/basics/src/url-connect.js index c82fd6139..787fe848d 100644 --- a/packages/basics/src/url-connect.js +++ b/packages/basics/src/url-connect.js @@ -62,7 +62,7 @@ export default async function URLConnect(data, feed) { await retry( async (bail, numberOfTimes) => { if (numberOfTimes > 1) { - debug('ezs')(`Attempts to reconnect (${numberOfTimes})`); + debug('ezs:debug')(`Attempts to reconnect (${numberOfTimes})`); } const controller = new AbortController(); const response = await fetch(url, { @@ -108,13 +108,15 @@ export default async function URLConnect(data, feed) { } catch (e) { if (!noerror) { - debug('ezs')( - `Break item #${this.getIndex()} [URLConnect] <${e}>`, + debug('ezs:warn')( + `Break item #${this.getIndex()} [URLConnect]`, + ezs.serializeError(e), ); feed.stop(e); } else { - debug('ezs')( - `Ignore item #${this.getIndex()} [URLConnect] <${e}>`, + debug('ezs:info')( + `Ignore item #${this.getIndex()} [URLConnect]`, + ezs.serializeError(e), ); } output.end(); diff --git a/packages/basics/src/url-fetch.js b/packages/basics/src/url-fetch.js index 45a87687d..8cb46ef82 100644 --- a/packages/basics/src/url-fetch.js +++ b/packages/basics/src/url-fetch.js @@ -74,10 +74,10 @@ export default async function URLFetch(data, feed) { } catch (e) { controller.abort(); if (noerror) { - debug('ezs')(`Ignore item #${this.getIndex()} [URLFetch] <${e}>`); + debug('ezs:info')(`Ignore item #${this.getIndex()} [URLFetch]`, this.ezs.serializeError(e)); return feed.send(data); } - debug('ezs')(`Break item #${this.getIndex()} [URLFetch] <${e}>`); + debug('ezs:warn')(`Break item #${this.getIndex()} [URLFetch]`, this.ezs.serializeError(e)); return feed.send(e); } } diff --git a/packages/basics/src/url-request.js b/packages/basics/src/url-request.js index 9b78338c9..a349cbf51 100644 --- a/packages/basics/src/url-request.js +++ b/packages/basics/src/url-request.js @@ -81,10 +81,10 @@ export default async function URLRequest(data, feed) { const onError = (e) => { controller.abort(); if (noerror) { - debug('ezs')(`Ignore item #${this.getIndex()} [URLRequest] <${e}>`); + debug('ezs:info')(`Ignore item #${this.getIndex()} [URLRequest]`, this.ezs.serializeError(e)); return feed.send(data); } - debug('ezs')(`Break item #${this.getIndex()} [URLRequest] <${e}>`); + debug('ezs:warn')(`Break item #${this.getIndex()} [URLRequest]`, this.ezs.serializeError(e)); return feed.send(e); }; try { diff --git a/packages/basics/src/url-stream.js b/packages/basics/src/url-stream.js index dd2b7505e..f4605794e 100644 --- a/packages/basics/src/url-stream.js +++ b/packages/basics/src/url-stream.js @@ -78,6 +78,7 @@ export default async function URLStream(data, feed) { if (this.isLast()) { return feed.close(); } + const { ezs } = this; const url = this.getParam('url'); const path = this.getParam('path', '*'); const retries = Number(this.getParam('retries', 5)); @@ -103,10 +104,10 @@ export default async function URLStream(data, feed) { const onError = (e) => { controller.abort(); if (noerror) { - debug('ezs')(`Ignore item #${this.getIndex()} [URLStream] <${e}>`); + debug('ezs:info')(`Ignore item #${this.getIndex()} [URLStream]`, ezs.serializeError(e)); return feed.send(data); } - debug('ezs')(`Break item #${this.getIndex()} [URLStream] <${e}>`); + debug('ezs:warn')(`Break item #${this.getIndex()} [URLStream]`, ezs.serializeError(e)); return feed.send(e); }; try { diff --git a/packages/basics/test/basics.js b/packages/basics/test/basics.js index b4adcbf74..8ac171139 100644 --- a/packages/basics/test/basics.js +++ b/packages/basics/test/basics.js @@ -115,7 +115,6 @@ describe('test', () => { res.push(chunk); }) .on('end', () => { - console.log(res); assert.equal(3, res.length); assert.equal('"a";"b";"c"\r\n', res[0]); assert.equal('"1";"2";"3"\r\n', res[1]); diff --git a/packages/basics/test/url-fetch.js b/packages/basics/test/url-fetch.js index b7809ff55..6cd6ea4e0 100644 --- a/packages/basics/test/url-fetch.js +++ b/packages/basics/test/url-fetch.js @@ -43,6 +43,10 @@ httpbin .post('/status/400') .reply(400); +httpbin + .get('/status/400') + .reply(400); + httpbin .post('/status/503') .reply(503); diff --git a/packages/conditor/src/corhal-fetch.js b/packages/conditor/src/corhal-fetch.js index e1e7842eb..4a5ef59bb 100644 --- a/packages/conditor/src/corhal-fetch.js +++ b/packages/conditor/src/corhal-fetch.js @@ -78,7 +78,7 @@ export default async function CORHALFetch(data, feed) { }; const onError = (e) => { controller.abort(); - debug('ezs')(`Break item #${this.getIndex()} [CORHALFetch] <${e}>`); + debug('ezs:warn')(`Break item #${this.getIndex()} [CORHALFetch]`, ezs.serializeError(e)); return feed.stop(e); }; const loop = async (stream, arr, afterKeyToken) => { @@ -102,7 +102,7 @@ export default async function CORHALFetch(data, feed) { const { headers: headersBis, body: noticesBis } = await responseBis.json(); loop(stream, noticesBis, headersBis['after-key-token']); } catch (e) { - console.error(`Error with ${url}/after/`, e.message, e.body); + debug('ezs:error')(`Error with ${url}/after/`, ezs.serializeError(e)); stream.end(); } } else { diff --git a/packages/conditor/src/wos-fetch.js b/packages/conditor/src/wos-fetch.js index 630a3f7b2..e3d497188 100644 --- a/packages/conditor/src/wos-fetch.js +++ b/packages/conditor/src/wos-fetch.js @@ -9,7 +9,7 @@ import writeTo from 'stream-write'; import each from 'async-each-series'; const request = (url, parameters) => async (bail, attempt) => { - debug('ezs')(`Request #${attempt} to ${url}`); + debug('ezs:debug')(`Request #${attempt} to ${url}`); const response = await fetch(url, parameters); if (!response.ok) { const { message } = await response.json(); @@ -87,7 +87,7 @@ export default async function WOSFetch(data, feed) { }; const onError = (e) => { controller.abort(); - debug('ezs')(`Break item #${this.getIndex()} [WOSFetch] <${e}>`); + debug('ezs:warn')(`Break item #${this.getIndex()} [WOSFetch]`, ezs.serializeError(e)); return feed.stop(e); }; const loop = async (stream, Records, reqPerSec, amtPerYear, QueryID, RecordsFound) => { @@ -98,7 +98,7 @@ export default async function WOSFetch(data, feed) { try { await write(stream, Records); } catch (e) { - console.error('Write Error', e.message); + debug('ezs:error')('Write Error', ezs.serializeError(e)); throw new Error(e); } } @@ -127,7 +127,7 @@ export default async function WOSFetch(data, feed) { } await loop(stream, RecordsBis, reqPerSec, amtPerYear, QueryID, RecordsFound); } catch (e) { - console.error(`Error with ${cURLBis.href}`, e.message); + debug('ezs:error')(`Error with ${cURLBis.href}`, ezs.serializeError(e)); throw new Error(e); } }; @@ -139,7 +139,7 @@ export default async function WOSFetch(data, feed) { const amtPerYear = response.headers.get('x-rec-amtperyear-remaining'); const QueryID = get(jsonResponse, 'QueryResult.QueryID'); const RecordsFound = get(jsonResponse, 'QueryResult.RecordsFound'); - debug('ezs')(`Query #${QueryID} should download ${RecordsFound} notices (Allowed downloads remaining : ${amtPerYear})`); + debug('ezs:debug')(`Query #${QueryID} should download ${RecordsFound} notices (Allowed downloads remaining : ${amtPerYear})`); await loop(output, [], reqPerSec, amtPerYear, QueryID, RecordsFound); await feed.flow(output); } catch (e) { diff --git a/packages/core/src/cli.js b/packages/core/src/cli.js index 72902cdd8..9b5bcd80e 100644 --- a/packages/core/src/cli.js +++ b/packages/core/src/cli.js @@ -5,19 +5,25 @@ import yargs from 'yargs'; import debug from 'debug'; import ezs from '.'; import File from './file'; -import { version } from '../package.json'; +import { VERSION, VERBOSE } from './constants'; import settings from './settings'; export default function cli(errlog) { const args = yargs .env('EZS') .usage('Usage: $0 [options] [|] [ ...]') - .version(version) + .version(VERSION) .options({ verbose: { alias: 'v', default: false, - describe: 'Enable debug mode with DEBUG=ezs', + describe: `Make ezs more talkative, which is equivalent to setting the envar to DEBUG=${VERBOSE}`, + type: 'boolean', + }, + logs: { + alias: 'l', + default: false, + describe: `Enable logs mode, which is equivalent to setting the envar to DEBUG_COLORS=0 DEBUG=${VERBOSE}`, type: 'boolean', }, tracer: { @@ -66,7 +72,11 @@ export default function cli(errlog) { const { argv } = args; if (argv.verbose) { - debug.enable('ezs'); + debug.enable(VERBOSE); + } + if (argv.logs) { + process.env.DEBUG_COLORS = 0; + debug.enable(VERBOSE); } if (argv.tracer) { settings.tracerEnable = true; @@ -85,7 +95,7 @@ export default function cli(errlog) { errlog(`Error: ${argv.daemon} doesn't exists.`); process.exit(1); } - debug('ezs')(`Serving ${serverPath} with ${settings.concurrency} shards`); + debug('ezs:debug')(`Serving ${serverPath} with ${settings.concurrency} shards`); return ezs.createCluster(settings.port, serverPath); } if (argv._.length === 0) { @@ -95,21 +105,21 @@ export default function cli(errlog) { let input; if (argv.env) { - debug('ezs')('Reading environment variables...'); + debug('ezs:info')('Reading environment variables...'); input = new PassThrough(ezs.objectMode()); input.write(process.env); input.end(); } else if (argv.file) { try { const filename = realpathSync(argv.file); - debug('ezs')(`Reading file ${filename} ...`); + debug('ezs:info')(`Reading file ${filename} ...`); input = createReadStream(filename); } catch (e) { errlog(`Error: ${argv.file} doesn't exists.`); process.exit(1); } } else { - debug('ezs')('Reading standard input...'); + debug('ezs:info')('Reading standard input...'); input = process.stdin; input.resume(); } diff --git a/packages/core/src/client.js b/packages/core/src/client.js index 40783d48d..aedaaf918 100644 --- a/packages/core/src/client.js +++ b/packages/core/src/client.js @@ -66,7 +66,7 @@ export const connectServer = (ezs) => (serverOptions, index) => { const output = new PassThrough(ezs.objectMode()); const handle = http.request(serverOptions, (res) => { connected = true; - debug('ezs')(`http://${hostname}:${port} send code ${res.statusCode}`); + debug('ezs:info')(`http://${hostname}:${port} send code ${res.statusCode}`); if (res.statusCode === 200) { res .pipe(ezs.uncompress(res.headers)) @@ -94,7 +94,7 @@ export const connectServer = (ezs) => (serverOptions, index) => { )); return output.end(); } - debug('ezs')(`http://${hostname}:${port} was stopped properly following ${e}`); + debug('ezs:info')(`http://${hostname}:${port} was stopped properly following`, ezs.serializeError(e)); return 4; }); handle.setNoDelay(false); diff --git a/packages/core/src/compactor.js b/packages/core/src/compactor.js index 3a3638e9b..9e4bfbd79 100644 --- a/packages/core/src/compactor.js +++ b/packages/core/src/compactor.js @@ -23,19 +23,19 @@ const z = chooseZ(); export function compressStream(ezs, opts = {}) { const encoding = opts['Content-Encoding'] || opts['content-encoding'] || 'identity'; if (typeof z.createGunzip === 'function' && encoding === 'gzip') { - debug('ezs')('ezs will use zlib to compress stream.'); + debug('ezs:debug')('ezs will use zlib to compress stream.'); return z.createGzip(); } - debug('ezs')('ezs will not compress stream.'); + debug('ezs:debug')('ezs will not compress stream.'); return new PassThrough(ezs.bytesMode()); } export function uncompressStream(ezs, opts = {}) { const encoding = opts['Content-Encoding'] || opts['content-encoding'] || 'identity'; if (typeof z.createGunzip === 'function' && encoding === 'gzip') { - debug('ezs')('ezs will use zlib to uncompress stream.'); + debug('ezs:debug')('ezs will use zlib to uncompress stream.'); return z.createGunzip(); } - debug('ezs')('ezs will not uncompress stream.'); + debug('ezs:debug')('ezs will not uncompress stream.'); return new PassThrough(ezs.bytesMode()); } diff --git a/packages/core/src/constants.js b/packages/core/src/constants.js index 4dd34e1af..831a92dbf 100644 --- a/packages/core/src/constants.js +++ b/packages/core/src/constants.js @@ -1,6 +1,7 @@ import filenameRegex from 'filename-regex'; import { version } from '../package.json'; +export const VERBOSE = 'ezs:*,-ezs:debug,-ezs:trace'; export const VERSION = version; export const STARTED_AT = Date.now(); export const RX_FILENAME = filenameRegex(); diff --git a/packages/core/src/engine.js b/packages/core/src/engine.js index f6decef39..099c47f90 100644 --- a/packages/core/src/engine.js +++ b/packages/core/src/engine.js @@ -51,17 +51,14 @@ function createErrorWith(error, index, funcName, funcParams, chunk) { const err = Error(msg); err.sourceError = error; err.sourceChunk = stringify(chunk); - err.toJSON = () => ({ - type: error.type || 'Standard error', - scope: error.scope || 'code', - date: error.date || new Date(), - message: msg.split('\n').shift(), - func: funcName, - params: funcParams, - traceback: stk.slice(0,10), - index, - chunk, - }); + err.type = error.type || 'Standard error'; + err.scope = error.scope || 'code'; + err.date = error.date || new Date(); + err.message = msg.split('\n').shift(); + err.func = funcName; + err.params = funcParams; + err.traceback = stk.slice(0,10); + err.index = index; Error.captureStackTrace(err, createErrorWith); return err; } @@ -115,7 +112,7 @@ export default class Engine extends SafeTransform { _transform(chunk, encoding, done) { const start = hrtime.bigint(); const next = () => { - if (debug.enabled('ezs')) { + if (debug.enabled('ezs:trace')) { this.ttime += (hrtime.bigint() - start); } done(); @@ -141,10 +138,10 @@ export default class Engine extends SafeTransform { this.index += 1; return this.queue(null, () => { const stop = hrtime.bigint(); - if (debug.enabled('ezs')) { + if (debug.enabled('ezs:trace')) { const cumulative = nano2sec(stop - this.stime); const elapsed = nano2sec(this.ttime); - debug('ezs')(`${cumulative}s cumulative ${elapsed}s elapsed for [${this.funcName}]`); + debug('ezs:trace')(`${cumulative}s cumulative ${elapsed}s elapsed for [${this.funcName}]`); } done(); }); @@ -171,7 +168,7 @@ export default class Engine extends SafeTransform { if (!this.errorWasSent) { this.errorWasSent = true; const warnErr = createErrorWith(error, currentIndex, this.funcName, this.params, chunk); - debug('ezs')('ezs engine emit an', warnErr); + debug('ezs:warn')('ezs engine emit an', this.ezs.serializeError(warnErr)); this.emit('error', warnErr); } }; @@ -180,7 +177,7 @@ export default class Engine extends SafeTransform { this.nullWasSent = true; this.nullWasSentError = createErrorWith(new Error('As a reminder, the end was recorded at this point'), currentIndex, this.funcName, this.params, chunk); } else if (this.nullWasSent && !this.errorWasSent) { - console.warn(createErrorWith(new Error('Oops, that\'s going to crash ?'), currentIndex, this.funcName, this.params, chunk)); + debug('ezs:warn')('Unstable state', this.ezs.serializeError(createErrorWith(new Error('Oops, that\'s going to crash ?'), currentIndex, this.funcName, this.params, chunk))); return warn(this.nullWasSentError); } if (!this.nullWasSent && this._readableState.ended) { @@ -188,7 +185,7 @@ export default class Engine extends SafeTransform { } if (data instanceof Error) { const ignoreErr = createErrorWith(data, currentIndex, this.funcName, this.params, chunk); - debug('ezs')(`Ignoring error at item #${currentIndex}`, ignoreErr); + debug('ezs:info')(`Ignoring error at item #${currentIndex}`, this.ezs.serializeError(ignoreErr)); return this.push(ignoreErr); } if (!this.errorWasSent) { @@ -206,13 +203,13 @@ export default class Engine extends SafeTransform { this.chunk = chunk; return Promise.resolve(this.func.call(this.scope, chunk, feed, this.scope)).catch((e) => { const asyncErr = createErrorWith(e, currentIndex, this.funcName, this.params, chunk); - debug('ezs')(`Async error thrown at item #${currentIndex}, pipeline is broken`, asyncErr); + debug('ezs:error')(`Async error thrown at item #${currentIndex}, pipeline is broken`, this.ezs.serializeError(asyncErr)); this.emit('error', asyncErr); done(); }); } catch (e) { const syncErr = createErrorWith(e, currentIndex, this.funcName, this.params, chunk); - debug('ezs')(`Sync error thrown at item #${currentIndex}, pipeline carries errors`, syncErr); + debug('ezs:error')(`Sync error thrown at item #${currentIndex}, pipeline carries errors`, this.ezs.serializeError(syncErr)); this.push(syncErr); return done(); } diff --git a/packages/core/src/feed.js b/packages/core/src/feed.js index 4394cd84c..d5bbcfd4d 100644 --- a/packages/core/src/feed.js +++ b/packages/core/src/feed.js @@ -1,4 +1,5 @@ import once from 'once'; +import debug from 'debug'; import retimer from 'retimer'; export default class Feed { @@ -85,7 +86,7 @@ export default class Feed { return new Promise((resolve) => { this.log('Feed.flow.stream.end'); stream.once('end', resolve);}); } log(x) { - //console.log(this.engine.funcName, x); + debug('ezs:debug')(this.engine.funcName, x); } end() { diff --git a/packages/core/src/file.js b/packages/core/src/file.js index 3dc1ee873..7fa553483 100644 --- a/packages/core/src/file.js +++ b/packages/core/src/file.js @@ -30,8 +30,8 @@ export function useFile(ezs, name) { if (plugName2) { return plugName2; } - debug('ezs')(`Unable to find '${name}' from ${plugName1}`); - debug('ezs')(`Unable to find '${name}' from ${plugName2}`); + debug('ezs:debug')(`Unable to find '${name}' from ${plugName1}`); + debug('ezs:debug')(`Unable to find '${name}' from ${plugName2}`); return false; } @@ -39,7 +39,7 @@ export function isFile(file) { try { return statSync(file).isFile(); } catch (e) { - debug('ezs')(`Unable to check '${file}'`); + debug('ezs:debug')(`Unable to check '${file}'`); return false; } } @@ -48,7 +48,7 @@ export default function File(ezs, name) { try { const filename = [findFileIn(ezs.getPath(), name), check(name)].filter(Boolean).shift(); if (!filename) { - debug('ezs')(`Unable to find '${name}' from ${filename}`); + debug('ezs:warn')(`Unable to find '${name}' from ${filename}`); return false; } ezs.addPath(dirname(filename)); diff --git a/packages/core/src/index.js b/packages/core/src/index.js index b7e1c6f39..f7be26feb 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -1,4 +1,5 @@ import { PassThrough } from 'readable-stream'; +import debug from 'debug'; import writeTo from 'stream-write'; import globalModules from 'global-modules'; import { resolve } from 'path'; @@ -22,6 +23,7 @@ const ezs = (name, options, environment) => new Engine(ezs, Statement.get(ezs, n const ezsPath = [resolve(__dirname, '../..'), process.cwd(), globalModules]; const ezsCache = new LRU(settings.cache); +ezs.serializeError = (err) => JSON.stringify(err, Object.getOwnPropertyNames(err).sort()); ezs.memoize = (key, func) => { if (!key || !settings.cacheEnable) { return func(); @@ -114,11 +116,11 @@ ezs.createPipeline = (input, commands, trap) => { } return output .pipe(ezs.catch((e) => { - trap.write(e.toJSON()); // see engine.js createErrorWith + trap.write(JSON.parse(ezs.serializeError(e))); // see engine.js createErrorWith return false; // do not catch the error })) .once('error', (e) => { - trap.write(e.toJSON()); // see engine.js createErrorWith + trap.write(JSON.parse(ezs.serializeError(e))); // see engine.js createErrorWith trap.end(); }) .once('end', () => { @@ -137,7 +139,7 @@ ezs.createTrap = (file, env) => { const input = ezs.createStream(ezs.objectMode()); ezs.createPipeline(input, ezs.compileCommands(ezs.createCommands({ file }), env)) .once('error', (e) => { - console.warn(`WARNING: the trap failed, ${file} stopped at ${e.message}`); + debug('ezs:warn')(`The trap failed, ${file} stopped`, ezs.serializeError(e)); }) .once('end', () => true) .on('data', () => true); diff --git a/packages/core/src/server/errorHandler.js b/packages/core/src/server/errorHandler.js index 41d934d16..6c806ea80 100644 --- a/packages/core/src/server/errorHandler.js +++ b/packages/core/src/server/errorHandler.js @@ -2,13 +2,14 @@ import debug from 'debug'; import JSONB from 'json-buffer'; import { httpRequestErrorTotal } from './metrics'; -const errorHandler = (request, response) => (error, code = 400) => { - debug('ezs')('Server has caught an error', code, error); +const errorHandler = (ezs, request, response) => (error, code = 400) => { + const stringError = ezs.serializeError(error); + debug('ezs:error')(`Server has caught an error #${code}`, stringError); httpRequestErrorTotal.labels(request.pathName).inc(); if (response.headersSent) { return response.end(); } - const bodyResponse = JSONB.stringify(error); + const bodyResponse = JSONB.stringify(JSON.parse(stringError)); response.writeHead(code, { 'Content-Type': 'application/json', 'Content-Length': bodyResponse.length, diff --git a/packages/core/src/server/index.js b/packages/core/src/server/index.js index 3c37e7bb2..83307800b 100644 --- a/packages/core/src/server/index.js +++ b/packages/core/src/server/index.js @@ -36,11 +36,11 @@ function methodMatch(values) { const signals = ['SIGINT', 'SIGTERM']; -function createServer(ezs, serverPort, serverPath, workerId) { +function createServer(ezs, serverPort, serverPath, worker) { const app = connect(); app.use( async (request, response, next) => { const stopTimer = httpRequestDurationMicroseconds.startTimer(); - request.workerId = workerId; + request.workerId = worker?.id; request.catched = false; request.serverPath = serverPath; request.urlParsed = parse(request.url, true); @@ -67,33 +67,38 @@ function createServer(ezs, serverPort, serverPath, workerId) { app.use((request, response, next) => { if (request.catched === false) { const error = new Error(`Unable to create middleware for ${request.method} ${request.pathName}`); - errorHandler(request, response)(error, 404); + errorHandler(ezs, request, response)(error, 404); } next(); }); app.use((error, request, response, next) => { - errorHandler(request, response)(error, 400); + errorHandler(ezs, request, response)(error, 400); next(); }); const server = controlServer(http.createServer(app)); + server.addListener('error', (error) => { + debug('ezs:error')(`Server with PID ${process.pid} fails`, ezs.serializeError(error)); + worker.kill(); + }); server.setTimeout(0); // default value, useful? server.requestTimeout = 0; // ezs has its own timeout see feed.timeout server.listen(serverPort); + server.addListener('connection', (socket) => { httpConnectionTotal.inc(); httpConnectionOpen.inc(); socket.on('error', (e) => { - debug('ezs')('Connection error, the server has stopped the request :', e.message); + debug('ezs:error')('Connection error, the server has stopped the request', ezs.serializeError(e)); }); socket.on('close', () => { httpConnectionOpen.dec(); }); }); signals.forEach((signal) => process.on(signal, () => { - debug('ezs')(`Signal received, stoping server with PID ${process.pid}`); + debug('ezs:info')(`Signal received, stoping server with PID ${process.pid}`); server.shutdown(() => process.exit(0)); })); - debug('ezs')(`Server starting with PID ${process.pid} and listening on port ${serverPort}`); + debug('ezs:info')(`Server starting with PID ${process.pid} and listening on port ${serverPort}`); return server; } @@ -104,8 +109,9 @@ function createCluster(ezs, serverPort, serverPath) { for (let i = 0; i < settings.concurrency; i += 1) { cluster.fork(); } - cluster.on('exit', () => { + cluster.on('exit', (worker, code, signal) => { if (!term) { + debug('ezs:info')(`Server with PID ${worker.process.pid} died with code=${code} signal=${signal}. restarting...`); cluster.fork(); } }); @@ -124,7 +130,7 @@ function createCluster(ezs, serverPort, serverPath) { res.end(); } })).listen(serverPort + 1); - debug('ezs')(`Cluster metrics server listening on port ${serverPort+1}`); + debug('ezs:info')(`Cluster metrics server listening on port ${serverPort+1}`); } signals.forEach((signal) => { process.on(signal, () => { @@ -136,7 +142,7 @@ function createCluster(ezs, serverPort, serverPath) { }); }); } else { - createServer(ezs, serverPort, serverPath, cluster.worker.id); + createServer(ezs, serverPort, serverPath, cluster.worker); } return cluster; } diff --git a/packages/core/src/server/knownPipeline.js b/packages/core/src/server/knownPipeline.js index d62c86f20..bae125d66 100644 --- a/packages/core/src/server/knownPipeline.js +++ b/packages/core/src/server/knownPipeline.js @@ -34,8 +34,8 @@ const knownPipeline = (ezs) => (request, response, next) => { const { headers, fusible, method, pathName } = request; const { query } = request.urlParsed; - debug('ezs')(`Create middleware 'knownPipeline' for ${method} ${pathName}`); - const triggerError = errorHandler(request, response); + debug('ezs:info')(`Create middleware 'knownPipeline' for ${method} ${pathName}`); + const triggerError = errorHandler(ezs, request, response); const files = ezs.memoize(`knownPipeline>${pathName}`, () => pathName .slice(1) @@ -46,7 +46,7 @@ const knownPipeline = (ezs) => (request, response, next) => { triggerError(new Error(`Cannot find ${pathName}`), 404); return false; } - debug('ezs')( + debug('ezs:debug')( `PID ${process.pid} will execute ${pathName} commands with ${sizeof(query)}B of global parameters`, ); diff --git a/packages/core/src/server/serverControl.js b/packages/core/src/server/serverControl.js index 1e51eddd5..95f4b24e2 100644 --- a/packages/core/src/server/serverControl.js +++ b/packages/core/src/server/serverControl.js @@ -6,7 +6,7 @@ const serverInformation = () => (request, response, next) => { return next(); } request.catched = true; - debug('ezs')(`Create middleware 'serverControl' for ${request.method} ${request.pathName}`); + debug('ezs:info')(`Create middleware 'serverControl' for ${request.method} ${request.pathName}`); const input = []; return request .on('error', err => next(err)) diff --git a/packages/core/src/server/serverInformation.js b/packages/core/src/server/serverInformation.js index abb275c66..0b43fb83c 100644 --- a/packages/core/src/server/serverInformation.js +++ b/packages/core/src/server/serverInformation.js @@ -54,7 +54,7 @@ const globalSwaggerPaths = { }; -const collectMetadata = async (dirPath, hostName) => { +const collectMetadata = async (ezs, dirPath, hostName) => { const globalSwagger = { openapi: '3.0.0', info: { @@ -171,7 +171,7 @@ const collectMetadata = async (dirPath, hostName) => { } } catch(e) { - debug('ezs')('Unable to load swagger.json', e); + debug('ezs:warn')('Unable to load swagger.json', ezs.serializeError(e)); return globalSwagger; } return globalSwagger; @@ -220,7 +220,7 @@ const collectPaths = async (ezs, dirPath) => { }; const collectAll = async (ezs, request) => { - const infos = await collectMetadata(request.serverPath, request.headers.host); + const infos = await collectMetadata(ezs, request.serverPath, request.headers.host); const paths = await collectPaths(ezs, request.serverPath); return ({ infos, paths }); }; @@ -230,7 +230,7 @@ const serverInformation = (ezs) => (request, response, next) => { return next(); } request.catched = true; - debug('ezs')(`Create middleware 'serverInformation' for ${request.method} ${request.pathName}`); + debug('ezs:info')(`Create middleware 'serverInformation' for ${request.method} ${request.pathName}`); return collectAll(ezs, request) .then(({ infos, paths }) => { diff --git a/packages/core/src/server/unknownPipeline.js b/packages/core/src/server/unknownPipeline.js index 6b00fe02a..9b2153ad9 100644 --- a/packages/core/src/server/unknownPipeline.js +++ b/packages/core/src/server/unknownPipeline.js @@ -9,7 +9,7 @@ const unknownPipeline = ezs => (request, response, next) => { return next(); } request.catched = true; - debug('ezs')(`Create middleware 'unknownPipeline' for ${request.method} ${request.pathName}`); + debug('ezs:info')(`Create middleware 'unknownPipeline' for ${request.method} ${request.pathName}`); const { headers } = request; response.setHeader('Content-Encoding', headers['content-encoding'] || 'identity'); @@ -28,7 +28,7 @@ const unknownPipeline = ezs => (request, response, next) => { }; }) .reduce((prev, cur) => Object.assign(prev, cur), {}); - debug('ezs')( + debug('ezs:debug')( `PID ${process.pid} will execute ${commands.length} commands with ${sizeof(environment)} of global parameters`, ); request @@ -36,7 +36,7 @@ const unknownPipeline = ezs => (request, response, next) => { .pipe(ezs('unpack')) .pipe(ezs('ungroup')) .pipe(ezs('delegate', { commands }, environment)) - .pipe(ezs.catch(errorHandler(request, response))) + .pipe(ezs.catch(errorHandler(ezs, request, response))) .pipe(ezs((input, output) => { if (!response.headersSent) { response.writeHead(200); diff --git a/packages/core/src/statement.js b/packages/core/src/statement.js index a7032ae35..8de017649 100644 --- a/packages/core/src/statement.js +++ b/packages/core/src/statement.js @@ -17,7 +17,7 @@ function load(ezs, name) { const after1 = Object.keys(pluginsList); const diff1 = after1.filter((item) => before1.indexOf(item) === -1); if (diff1.length > 0) { - debug('ezs')(`These statements are registered: ${diff1.join(',')}`); + debug('ezs:debug')(`These statements are registered: ${diff1.join(',')}`); } } diff --git a/packages/core/src/statements/breaker.js b/packages/core/src/statements/breaker.js index 8cf1267d1..e11f8ed8f 100644 --- a/packages/core/src/statements/breaker.js +++ b/packages/core/src/statements/breaker.js @@ -17,7 +17,7 @@ export default async function breaker(data, feed) { } const check = await checkFusible(this.fusible); if (!check) { - debug('ezs')(`Stream break, ${this.fusible} no longer active.`); + debug('ezs:info')(`Stream break, ${this.fusible} no longer active.`); return feed.close(data); } return feed.send(data); diff --git a/packages/core/src/statements/combine.js b/packages/core/src/statements/combine.js index dcf641fac..3a93e7ffa 100644 --- a/packages/core/src/statements/combine.js +++ b/packages/core/src/statements/combine.js @@ -112,7 +112,6 @@ export default async function combine(data, feed) { makeDir.sync(this.cachePath); } } - debug('ezs')('[combine] with sub pipeline.'); const primer = this.getParam('primer', 'n/a'); const commands = ezs.createCommands({ file: this.getParam('file'), @@ -123,6 +122,7 @@ export default async function combine(data, feed) { append: this.getParam('append'), }); this.databaseID = hashCoerce.hash({ primer, commands }); + debug('ezs:debug')(`[combine] with sub pipeline #${this.databaseID}`); const input = ezs.createStream(ezs.objectMode()); this.database = {}; let stream; diff --git a/packages/core/src/statements/debug.js b/packages/core/src/statements/debug.js index 60c0ca640..250d8dce0 100644 --- a/packages/core/src/statements/debug.js +++ b/packages/core/src/statements/debug.js @@ -1,58 +1,30 @@ -import util from 'util'; import debugGlobal from 'debug'; import _ from 'lodash'; /** - * Take `Object`, print it (with its number), and throw the same object. - * - * with ezs debug enabled: - * every object will be stringify for printed and all others ezs debug traces will be print - * - * with ezs debug disabled: - * every objects will be inspected (indented and colorized) and print on stderr (error level) or stdout (log level) - * - * if ezs parameter is set, every object are not log (it's a global action) + * Take `Object`, print it (with its number index), and throw the same object. * * @name debug - * @param {String} [level=error] console level : log or error or silent + * @param {String} [level=info] DEBUG ezs level (depends of DEBUG env variable) * @param {String} [text=valueOf] text before the dump * @param {String} [path] path of field to print - * @param {Boolean} [ezs] enable or disable ezs global debug traces + * @param {Boolean} [namespaces=ezs:*,-ezs:debug,-ezs:trace] set DEBUG namespaces * @returns {Object} */ export default function debug(data, feed) { if (this.isLast()) { return feed.send(data); } - const level = String(this.getParam('level', 'error')); + const levelRaw = String(this.getParam('level', 'info')); + const level = ['trace', 'debug', 'info', 'warn', 'error'].includes(levelRaw) ? levelRaw : 'info'; const text = String(this.getParam('text', 'valueOf')); const path = this.getParam('path', []); const keys = Array.isArray(path) ? path : [path]; const output = keys.length === 0 ? data : _.pick(data, keys); - const mode = this.getParam('ezs', null); - if (mode !== null) { - if (Boolean(mode) === true && debugGlobal.enabled('ezs') === false) { - debugGlobal.enable('ezs'); - } - if (Boolean(mode) === false && debugGlobal.enabled('ezs') === true) { - debugGlobal.enable('-ezs'); - } - return feed.send(data); - } const logTitle = text.concat('#').concat(this.getIndex()).concat(' ->'); - if (debugGlobal.enabled('ezs')) { - if (mode === null) { - debugGlobal('ezs')(logTitle, JSON.stringify(output)); - } - return feed.send(data); - } - // eslint-disable-next-line - const logFunc = console[level]; - if (typeof logFunc === 'function') { - const logOpts = { showHidden: false, depth: 3, colors: true }; - const logDetails = util.inspect(output, logOpts); - logFunc(logTitle, logDetails); - } + const debugPrefix = `ezs:${level}`; + + debugGlobal(debugPrefix)(`${logTitle} %j`, output); return feed.send(data); } diff --git a/packages/core/src/statements/dedupe.js b/packages/core/src/statements/dedupe.js index 2ea0372c9..23bda54c1 100644 --- a/packages/core/src/statements/dedupe.js +++ b/packages/core/src/statements/dedupe.js @@ -1,4 +1,5 @@ import _ from 'lodash'; +import debug from 'debug'; /** * Take `Object`, and check that the object identifier has not already been used previously * @@ -20,14 +21,14 @@ export default async function dedupe(data, feed) { } if (uri === check) { if (ignore) { - console.warn(`WARNING: ${path} field not exists, item #${this.getIndex()} was ignored` ); + debug('ezs:warn')(`${path} field not exists, item #${this.getIndex()} was ignored` ); return feed.end(); } return feed.send(new Error(`${path} field not exists, enable to dedupe.`)); } if (this.previousURI[uri] === true) { if (ignore) { - console.warn(`WARNING: ${uri} already exists, item #${this.getIndex()} was ignored` ); + debug('ezs:warn')(`${uri} already exists, item #${this.getIndex()} was ignored` ); return feed.end(); } return feed.send(new Error(`Duplicate identifier: ${uri} already exists`)); diff --git a/packages/core/src/statements/delegate.js b/packages/core/src/statements/delegate.js index 8f1778af6..34fbf771a 100644 --- a/packages/core/src/statements/delegate.js +++ b/packages/core/src/statements/delegate.js @@ -32,7 +32,7 @@ export default function delegate(data, feed) { this.whenFinish = feed.flow(output, { autoclose: true }); } if (this.isLast()) { - debug('ezs')(`${this.getIndex()} chunks have been delegated`); + debug('ezs:debug')(`${this.getIndex()} chunks have been delegated`); this.whenFinish.finally(() => feed.close()); return this.input.end(); } diff --git a/packages/core/src/statements/dispatch.js b/packages/core/src/statements/dispatch.js index 25aa6eb85..7b5242d17 100644 --- a/packages/core/src/statements/dispatch.js +++ b/packages/core/src/statements/dispatch.js @@ -38,7 +38,7 @@ export default function dispatch(data, feed) { ) { return feed.stop(new Error('Invalid parmeter for [dispatch]')); } - debug('ezs')(`[dispatch] connect to #${servers.length} servers.`); + debug('ezs:debug')(`[dispatch] connect to #${servers.length} servers.`); const handles = servers.map(connectServer(ezs)); this.ins = handles.map((h) => h[0]); this.outs = handles.map((h) => h[1]); diff --git a/packages/core/src/statements/fork.js b/packages/core/src/statements/fork.js index 81c86339e..44438cce2 100644 --- a/packages/core/src/statements/fork.js +++ b/packages/core/src/statements/fork.js @@ -84,7 +84,7 @@ export default async function fork(data, feed) { } } if (this.isLast()) { - debug('ezs')(`${this.getIndex()} chunks have been delegated`); + debug('ezs:debug')(`${this.getIndex()} chunks have been delegated`); this.input.end(); if (standalone) { feed.close(); diff --git a/packages/core/src/statements/map.js b/packages/core/src/statements/map.js index c2bdd023f..d1d9bf5dc 100644 --- a/packages/core/src/statements/map.js +++ b/packages/core/src/statements/map.js @@ -1,4 +1,5 @@ import _ from 'lodash'; +import debug from 'debug'; import from from 'from'; /** @@ -44,7 +45,7 @@ export default function map(data, feed) { return output .pipe(ezs.catch()) .on('error', (error) => { - console.warn(`WARNING: map ignore a item (${error})`); + debug('ezs:warn')('Map ignore a item', ezs.serializeError(error)); feed.send(error); }) .on('data', (chunk) => { diff --git a/packages/core/src/statements/parallel.js b/packages/core/src/statements/parallel.js index 1a740ee67..ab623fa2d 100644 --- a/packages/core/src/statements/parallel.js +++ b/packages/core/src/statements/parallel.js @@ -36,7 +36,7 @@ export default function parallel(data, feed) { if (!commands || commands.length === 0) { return feed.stop(new Error('Invalid parmeter for [parallel]')); } - debug('ezs')(`[parallel] start with #${concurrency} workers.`); + debug('ezs:debug')(`[parallel] start with #${concurrency} workers.`); const logger = ezs.createTrap(this.getParam('logger'), this.getEnv()); const handles = Array(concurrency).fill(true).map(duplexer(ezs, commands, environment, logger)); this.ins = handles.map((h) => h[0]); diff --git a/packages/core/src/statements/singleton.js b/packages/core/src/statements/singleton.js index 26612a1b7..4b046ccd7 100644 --- a/packages/core/src/statements/singleton.js +++ b/packages/core/src/statements/singleton.js @@ -18,7 +18,7 @@ export default function singleton(data, feed) { } if (this.isFirst()) { const { ezs } = this; - debug('ezs')('[singleton] starting once with one object.'); + debug('ezs:debug')('[singleton] starting once with one object.'); const savedData = { ...data }; let result = {}; const input = ezs.createStream(ezs.objectMode()); diff --git a/packages/core/src/statements/swing.js b/packages/core/src/statements/swing.js index 76c26d843..9b306e960 100644 --- a/packages/core/src/statements/swing.js +++ b/packages/core/src/statements/swing.js @@ -37,7 +37,7 @@ export default function swing(data, feed) { this.whenFinish = feed.flow(output); } if (this.isLast()) { - debug('ezs')(`${this.getIndex()} chunks have been delegated`); + debug('ezs:debug')(`${this.getIndex()} chunks have been delegated`); this.whenFinish.finally(() => feed.close()); return this.input.end(); } diff --git a/packages/core/src/statements/unpack.js b/packages/core/src/statements/unpack.js index bb7556f95..7ff515ad0 100644 --- a/packages/core/src/statements/unpack.js +++ b/packages/core/src/statements/unpack.js @@ -40,7 +40,7 @@ export default function unpack(data, feed) { const lineParsed = JSON.parse(line); return feed.write(lineParsed); } catch(e) { - debug('ezs')(`[unpack] Syntax error at #${this.getIndex()+1} with ${line}`); + debug('ezs:warn')(`[unpack] Syntax error at #${this.getIndex()+1} with ${line}`, this.ezs.serializeError(e)); return feed.stop(e); } }); diff --git a/packages/core/test/expand.js b/packages/core/test/expand.js index 530d159e1..1d2512286 100644 --- a/packages/core/test/expand.js +++ b/packages/core/test/expand.js @@ -1,4 +1,5 @@ import fs from 'fs'; +import debug from 'debug'; import from from 'from'; import { PassThrough } from 'stream'; import ezs from '../src'; @@ -513,7 +514,12 @@ test('with a buggy script', (done) => { output.push(chunk); }) .on('error', (e) => { - expect(e.message).toEqual(expect.stringContaining('BADVAL is not defined')); + try { + expect(e.message).toEqual(expect.stringContaining('Lodash')); + } + catch (ee) { + done(ee); + } expect(output.length).toEqual(0); done(); }) diff --git a/packages/core/test/ezs.js b/packages/core/test/ezs.js index dff5199c2..11e13198d 100644 --- a/packages/core/test/ezs.js +++ b/packages/core/test/ezs.js @@ -1,6 +1,7 @@ import assert from 'assert'; import Dir from 'path'; import from from 'from'; +import debug from 'debug'; import fs from 'fs'; import { Readable, PassThrough } from 'stream'; import ezs from '../src'; @@ -54,40 +55,45 @@ describe('Build a pipeline', () => { }); }); it('with debug transformation', (done) => { + debug.enable('ezs:*'); + const namespaces = debug.disable(); let res = 0; const ten = new Decade(); + const script = ` + [replace] + path = a + value = z + path = b + value = self() + path = c + value = none + [debug] + path = a + path = b + `; ten .pipe(ezs((input, output) => { output.send(input); })) .pipe(ezs('tracer')) - .pipe(ezs('debug', { - text: 'Debug message (ezs = true)', - ezs: true, - })) .pipe(ezs('debug', { text: 'Debug message', })) .pipe(ezs('debug', { - text: 'Debug message (ezs = false)', - ezs: false, - })) - .pipe(ezs('debug', { - text: 'Debug message (level = log)', + text: 'Debug message (unexsiting level)', level: 'log', })) .pipe(ezs('debug', { - text: 'Debug message (level = error)', - })) - .pipe(ezs('debug', { - text: 'Debug message (level = silent)', - level: 'silent', + text: 'Debug message (level = trace)', + level: 'trace', })) + .pipe(ezs('delegate', { script })) .on('data', (chunk) => { - res += chunk; + res += chunk.b; }) .on('end', () => { assert.strictEqual(res, 45); + debug.enable(namespaces); done(); }); }); diff --git a/packages/core/test/overturn.js b/packages/core/test/overturn.js index f81f89e3f..b94301734 100644 --- a/packages/core/test/overturn.js +++ b/packages/core/test/overturn.js @@ -205,8 +205,12 @@ test('with a buggy script', (done) => { output.push(chunk); }) .on('error', (e) => { - expect(e.message).toEqual(expect.stringContaining('BADVAL is not defined')); - expect(output.length).toEqual(0); + try { + expect(e.message).toEqual(expect.stringContaining('Lodash')); + expect(output.length).toEqual(0); + } catch (ee) { + done(ee); + } done(); }) .on('end', () => { diff --git a/packages/spawn/package.json b/packages/spawn/package.json index c9cf389a2..fb08f73bb 100644 --- a/packages/spawn/package.json +++ b/packages/spawn/package.json @@ -5,6 +5,7 @@ "author": "Nicolas Thouvenin ", "bugs": "https://github.com/Inist-CNRS/ezs/issues", "dependencies": { + "debug": "4.3.3", "semver": "7.5.2", "stream-iterate": "1.2.0" }, diff --git a/packages/spawn/src/exec.js b/packages/spawn/src/exec.js index b36fefeec..189aabca1 100644 --- a/packages/spawn/src/exec.js +++ b/packages/spawn/src/exec.js @@ -1,3 +1,4 @@ +import debug from 'debug'; import pool from './pool'; /** @@ -38,6 +39,7 @@ export default async function exec(data, feed) { let handle; try { + debug('ezs:info')(`Startup pool for ${command} with ${concurrency} process`); handle = await pool.startup(concurrency, command, args); if (!this.resource) { this.input = ezs.createStream(ezs.objectMode()); diff --git a/packages/storage/src/load.js b/packages/storage/src/load.js index a6be298a5..8fb72ff01 100644 --- a/packages/storage/src/load.js +++ b/packages/storage/src/load.js @@ -1,4 +1,5 @@ import { get, set } from 'lodash'; +import debug from 'debug'; import store from './store'; /** @@ -10,6 +11,7 @@ import store from './store'; * @returns {String} */ export default async function load(data, feed) { + const { ezs } = this; const location = this.getParam('location'); const pathName = this.getParam('path', 'uri'); const path = Array.isArray(pathName) ? pathName.shift() : pathName; @@ -29,7 +31,7 @@ export default async function load(data, feed) { return feed.close(); } if (!uri) { - console.warn(`WARNING: uri was empty, [load] item #${this.getIndex()} was ignored`); + debug('ezs:warn')(`uri was empty, [load] item #${this.getIndex()} was ignored`); return feed.send(data); } const value = await this.store.get(uri); @@ -40,7 +42,7 @@ export default async function load(data, feed) { return feed.send(value); } catch(e) { if (e.code === 'ENOENT') { - console.warn(`WARNING: uri not found (${uri}), item #${this.getIndex()} was ignored`, e); + debug('ezs:warn')(`uri not found (${uri}), item #${this.getIndex()} was ignored`, ezs.serializeError(e)); if (target) { set(data, target, undefined); return feed.send(data); diff --git a/packages/storage/src/save.js b/packages/storage/src/save.js index 77427ee3b..59ff61a3b 100644 --- a/packages/storage/src/save.js +++ b/packages/storage/src/save.js @@ -1,4 +1,5 @@ import { get } from 'lodash'; +import debug from 'debug'; import store from './store'; /** @@ -33,7 +34,7 @@ export default async function save(data, feed) { await this.store.reset(); } if (!uri) { - console.warn(`WARNING: uri was empty, [save] item #${this.getIndex()} was ignored`); + debug('ezs:warn')(`uri was empty, [save] item #${this.getIndex()} was ignored`); return feed.send(data); } await this.store.put(uri, data, score); diff --git a/packages/store/src/store.js b/packages/store/src/store.js index 58f519254..8979e2071 100644 --- a/packages/store/src/store.js +++ b/packages/store/src/store.js @@ -37,7 +37,7 @@ class Store { this.created = true; makeDir.sync(this.directory); } - debug('ezs')(`DB from ${this.directory}`, (this.created ? 'was created' : 'already exists')); + debug('ezs:info')(`DB from ${this.directory}`, (this.created ? 'was created' : 'already exists')); this.ready = new Promise((resolve, reject) => { if (!handle[this.directory]) { levelup(leveldown(this.directory), {}, (err, db) => { @@ -97,14 +97,14 @@ class Store { return db.get(key2, (err1, value) => { if (err1) { if (err1.notFound) { - console.error('WARNING', err1); + debug('ezs:warn')('Not Found', this.ezs.serializeError(err1)); return resolve(null); } return reject(err1); } return db.del(key2, (err2) => { if (err2) { - console.error('WARNING', err2); + debug('ezs:warn')('Unable to delete', this.ezs.serializeError(err2)); } return resolve(decodeValue(value)); }); @@ -208,10 +208,10 @@ class Store { async close() { const db = await this.connect(); - debug('ezs')(`DB from ${this.directory} is closing`); + debug('ezs:info')(`DB from ${this.directory} is closing`); delete handle[this.directory]; if (!this.persistent) { - debug('ezs')(`DB from ${this.directory} is clearing`); + debug('ezs:info')(`DB from ${this.directory} is clearing`); await db.clear(); await db.close(); await del([this.directory], { force: true }); diff --git a/packages/transformers/src/operations/PARSE.js b/packages/transformers/src/operations/PARSE.js index 656ef1574..1525b3a57 100644 --- a/packages/transformers/src/operations/PARSE.js +++ b/packages/transformers/src/operations/PARSE.js @@ -7,7 +7,6 @@ export const parse = value => { try { return JSON.parse(value); } catch (e) { - console.error(e); return value; } };