Skip to content

Commit

Permalink
fix: 🐛 add debug information to unpack statement
Browse files Browse the repository at this point in the history
  • Loading branch information
touv committed Jul 17, 2023
1 parent 9abd975 commit 512a128
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/core/src/statements/unpack.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import debug from 'debug';

const eol = '\n';

/**
Expand Down Expand Up @@ -28,7 +30,13 @@ export default function unpack(data, feed) {
}
this.remainder = lines.pop();
lines.filter(Boolean).forEach((line) => {
feed.write(JSON.parse(line));
try {
const lineParsed = JSON.parse(line);
return feed.write(lineParsed);
} catch(e) {
debug('ezs')(`[unpack] Syntax error at #${this.getIndex()+1} with <line>${line}</line>`);
return feed.stop(e);
}
});
return feed.end();
}
19 changes: 19 additions & 0 deletions packages/core/test/statements.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,25 @@ describe('statements', () => {
done();
});
});
it('unpack#4', (done) => {
const input = [
'"aaa"\nbbb"\n"ccc"\n',
'"ddd"\n"eee"\n"fff"',
];
from(input)
.pipe(ezs('unpack'))
.pipe(ezs.catch())
.on('error', (e) => {
expect(e.message).toEqual(expect.stringContaining('SyntaxError'));
done();
})
.on('data', (item) => {
assert.equal(item, 'aaa');
})
.on('end', () => {
done(new Error('Error is the right behavior'));
});
});
it('truncate#1', (done) => {
const res = [];
from(['aa', 'bb', 'cc', 'dd', 'ee'])
Expand Down

0 comments on commit 512a128

Please sign in to comment.