blake-regalia / graphy.js

A collection of RDF libraries for JavaScript
https://graphy.link/
ISC License
161 stars 3 forks source link

Cannot read property 'error' of undefined #22

Closed LaurensRietveld closed 4 years ago

LaurensRietveld commented 4 years ago

I've got a test.nt file that contains this line:

<A-Ha:Top/Arts/Music/Bands_and_Artists/A/A-Ha> <http://dmoz.org/rdf/Target> <http://jena.cvs.sourceforge.net/viewvc/*checkout*/jena/jena-perf/data/Top/Arts/Music/Bands_and_Artists/A/A-Ha> .

When I run this script:

const fs = require('fs');
const nt_read = require('@graphy/content.nt.read');

let count = 0;
fs.createReadStream('test.nt')
    .pipe(nt_read())
    .on('data', (y_quad) => {
    count++;
    })
    .on('error', console.error)
    .on('eof', () => {
        console.log('done!', count);
    });

Then I get this error:

TypeError: Cannot read property 'error' of undefined
    at create_named_node_escapeless (/scratch/lrd900/node/node_modules/@graphy/content.nt.read/main.js:300:66)
    at Reader.statement (/scratch/lrd900/node/node_modules/@graphy/content.nt.read/main.js:635:20)
    at Reader.parse (/scratch/lrd900/node/node_modules/@graphy/content.nt.read/main.js:519:21)
    at NTriples_Reader.transform [as _transform] (/scratch/lrd900/node/node_modules/@graphy/content.nt.read/main.js:370:11)
    at NTriples_Reader.Transform._read (/scratch/lrd900/node/node_modules/readable-stream/lib/_stream_transform.js:177:10)
    at NTriples_Reader.Transform._write (/scratch/lrd900/node/node_modules/readable-stream/lib/_stream_transform.js:164:83)
    at doWrite (/scratch/lrd900/node/node_modules/readable-stream/lib/_stream_writable.js:409:139)
    at writeOrBuffer (/scratch/lrd900/node/node_modules/readable-stream/lib/_stream_writable.js:398:5)
    at NTriples_Reader.Writable.write (/scratch/lrd900/node/node_modules/readable-stream/lib/_stream_writable.js:307:11)
    at ReadStream.ondata (_stream_readable.js:728:22)
blake-regalia commented 4 years ago

Fixed in v4.0.4.

The reader will now err about the invalid IRI, which can either be caught in the 'error' event handler, or bypassed altogether using the relax option to the reader to skip IRI validation. Is this the behavior you expected?

LaurensRietveld commented 4 years ago

That's what I'd expect indeed, thanks! :+1: