0

I'm using an ID3 tag reader library https://github.com/43081j/id3 & the example function to call is in this format...

id3(this.files[0], function(err, tags) {
  console.log(err, tags);
});

It works great for most files but from time to time there is an error like this

Uncaught URIError: URI malformed

I've tried to wrap this function in a try...catch to catch the error like this

try {
  id3(file, function(err, tags) {
    if (err) throw err;
    console.log('tags .. ' + tags);
  });
}
catch (e) {
  console.log('caught it!');
}

But in fact the error still manages to remain uncaught.

I think it might be to do with the fact that the function is asynchronous, but am really struggling to understand how to prevent this and catch the error.

Ultimately I want to wrap the entire function in a promise, something like this:

return new Promise(function(resolve, reject) {
  try {
    id3(file, function(err, tags) {
      if(err) throw err
      resolve(tags);
    });
  }
  catch (err) {
    reject('blank');
  }
}

but no matter what I try the reject method never gets called on an error.

Thanks!

Chris
  • 1,054
  • 2
  • 12
  • 24

0 Answers0