Skip to content

Commit

Permalink
fix: 🐛 the right error for wrong location
Browse files Browse the repository at this point in the history
  • Loading branch information
touv committed Jan 5, 2022
1 parent 22e1005 commit 1337817
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 7 deletions.
4 changes: 3 additions & 1 deletion packages/analytics/src/combine.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ export default function combine(data, feed) {
return feed.send(data);
})
.catch((e) => {
this.store.close();
if (this.store) {
this.store.close();
}
feed.stop(e);
});
}
4 changes: 3 additions & 1 deletion packages/analytics/src/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ export default async function expand(data, feed) {
}
return feed.end();
} catch (e) {
this.store.close();
if (this.store) {
this.store.close();
}
return feed.stop(e);
}
}
36 changes: 36 additions & 0 deletions packages/analytics/test/combine.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,40 @@ describe('no combine', () => {
done(new Error('Error is the right behavior'));
});
});
test('with wrong location', (done) => {
ezs.use(statements);
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 = fix({id:'a', value:'aa'},{id:'b', value:'bb'},{id:'c', value:'cc'},{id:'d', value:'dd'},{id:'e', value:'ee'},{id:'f', value:'ff'})
[exploding]
[value]
`;

from(input)
.pipe(ezs('combine', { path: 'b', script, location: '/no/where' }))
.pipe(ezs.catch())
.on('error', (e) => {
expect(e.message).toEqual(expect.stringContaining('EACCES: permission denied'));
done();
})
.on('data', () => {
done(new Error('Error is the right behavior'));
})
.on('end', () => {
done(new Error('Error is the right behavior'));
});
});
});
43 changes: 38 additions & 5 deletions packages/analytics/test/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ test('with error script', (done) => {
.pipe(ezs.catch())
.on('error', (e) => {
fs.unlinkSync(filename);
expect(e).toEqual(expect.not.stringContaining('permission denied'));
expect(e.message).toEqual(expect.stringContaining('permission denied'));
done();
})
.on('end', () => {
Expand All @@ -233,7 +233,7 @@ test('with no script', (done) => {
.pipe(ezs('expand', { path: 'b' }))
.pipe(ezs.catch())
.on('error', (e) => {
expect(e).toEqual(expect.not.stringContaining('Invalid parmeter'));
expect(e.message).toEqual(expect.stringContaining('Invalid parmeter'));
done();
})
.on('data', () => {
Expand All @@ -243,6 +243,39 @@ test('with no script', (done) => {
done(new Error('Error is the right behavior'));
});
});
test('with wrong location ', (done) => {
ezs.use(statements);
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
[assign]
path = value
value = get('value').toUpper()
`;
from(input)
.pipe(ezs('expand', { path: 'b', script, location: '/no/where' }))
.pipe(ezs.catch())
.on('error', (e) => {
expect(e.message).toEqual(expect.stringContaining('EACCES: permission denied'));
done();
})
.on('data', () => {
done(new Error('Error is the right behavior'));
})
.on('end', () => {
done(new Error('Error is the right behavior'));
});
});

test('with no path', (done) => {
ezs.use(statements);
const input = [
Expand Down Expand Up @@ -387,7 +420,7 @@ test('with a script that loses the identifier', (done) => {
.pipe(ezs('expand', { path: 'b', script }))
.pipe(ezs.catch())
.on('error', (e) => {
expect(e).toEqual(expect.not.stringContaining('key cannot be `null`'));
expect(e.message).toEqual(expect.stringContaining('key cannot be `null`'));
done();
})
.on('end', () => {
Expand Down Expand Up @@ -421,7 +454,7 @@ test('with a script that break the identifier #1', (done) => {
})
.on('error', (e) => {
expect(output.length).toEqual(0);
expect(e).toEqual(expect.not.stringContaining('id was corrupted'));
expect(e.message).toEqual(expect.stringContaining('id was corrupted'));
done();
})
.on('end', () => {
Expand Down Expand Up @@ -458,7 +491,7 @@ test('with a script that break the identifier #2', (done) => {
})
.on('error', (e) => {
expect(output.length).toEqual(1);
expect(e).toEqual(expect.not.stringContaining('id was corrupted'));
expect(e.message).toEqual(expect.stringContaining('id was corrupted'));
done();
})
.on('end', () => {
Expand Down

0 comments on commit 1337817

Please sign in to comment.