Skip to content

Commit

Permalink
Merge pull request #392 from Inist-CNRS/identify-undefined
Browse files Browse the repository at this point in the history
fix: 🐛 with undefined data
  • Loading branch information
touv authored Dec 19, 2023
2 parents 8240602 + 12b14c0 commit 67b5d3b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
25 changes: 15 additions & 10 deletions packages/core/src/statements/identify.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,22 @@ export default async function identify(data, feed) {
if (this.isLast()) {
return feed.close();
}
if (!validKey(uri)) {
let identifier;
if (scheme === 'uid') {
identifier = await generate(nolookalikes, 8);
} else if (scheme === 'sha') {
identifier = await sha(JSON.stringify(data));
}
if (identifier) {
const checksum = ncda(identifier, nolookalikes);
_.set(data, path, `${scheme}:/${identifier}${checksum}`);
try {
if (!validKey(uri)) {
let identifier;
if (scheme === 'uid') {
identifier = await generate(nolookalikes, 8);
} else if (scheme === 'sha') {
identifier = await sha(data);
}
if (identifier) {
const checksum = ncda(identifier, nolookalikes);
_.set(data, path, `${scheme}:/${identifier}${checksum}`);
}
}
}
catch (e) {
return feed.stop(e);
}
return feed.send(data);
}
23 changes: 23 additions & 0 deletions packages/core/test/identify.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,29 @@ describe('[identify]', () => {
done();
});
});

it('identify #2', (done) => {
from([
{ id: 1, b: 'a' },
undefined,
{ id: 1, b: 'a' },
])
.pipe(ezs('identify', { path: 'uuid', scheme: 'sha' }))
.pipe(ezs.catch())
.on('error', (e) => {
try {
expect(e.message).toEqual(expect.stringContaining('Received undefined'));
done();
} catch(ee) {
done(ee);
}
})
.on('data', () => true)
.on('end', () => {
done(new Error('Error is the right behavior'));
});
});

});

describe('validKey', () => {
Expand Down

0 comments on commit 67b5d3b

Please sign in to comment.