From 6f3115709fa0f9f59875103d45dcc8f65f102372 Mon Sep 17 00:00:00 2001 From: Nicolas Thouvenin Date: Thu, 16 Jul 2020 17:19:23 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20attempts=20to=20fix=20tr?= =?UTF-8?q?avis=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/analytics/src/expand.js | 8 +++++--- packages/analytics/test/expand.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/analytics/src/expand.js b/packages/analytics/src/expand.js index 4375506f..8104294b 100644 --- a/packages/analytics/src/expand.js +++ b/packages/analytics/src/expand.js @@ -69,10 +69,12 @@ export default async function expand(data, feed) { const output = ezs.createPipeline(this.input, statements) .pipe(ezs.catch()) .on('data', async ({ id, value }) => { - const obj = await this.store.get(id); - if (obj) { + try { + const obj = await this.store.get(id); set(obj, path, value); feed.write(obj); + } catch (e) { + feed.stop(e); } }) .on('error', (e) => feed.stop(e)); @@ -80,7 +82,7 @@ export default async function expand(data, feed) { } if (this.isLast()) { return whenFinish - .then(async () => { + .then(() => { this.store.close(); return feed.close(); }) diff --git a/packages/analytics/test/expand.js b/packages/analytics/test/expand.js index 019365f0..08f1a90d 100644 --- a/packages/analytics/test/expand.js +++ b/packages/analytics/test/expand.js @@ -203,4 +203,32 @@ describe('no expand', () => { done(); }); }); + test('with a script that loses the identifier', (done) => { + const input = [ + { a: 1, b: 'a' }, + { a: 2, b: 'b' }, + { a: 3, b: 'c' }, + { a: 4, b: 'd' }, + { a: 5, b: 'e' }, + { a: 6, b: 'f' }, + ]; + const script = ` + [use] + plugin = analytics + + [replace] + path = value + value = get('value').toUpper() + `; + + from(input) + .pipe(ezs('expand', { path: 'b', script })) + .pipe(ezs.catch()) + .on('error', () => { + done(); + }) + .on('end', () => { + done(new Error('Error is the right behavior')); + }); + }); });