1

I use the module omdb and I have some trouble catching errors when using it. The error is caused by one of the two methods below, but the stacktrace does not show which. Furthermore, none of the console.logs fires either, so I assume that I've made some mistake trying to handle possible errors. The description for omdb.poster is:

Returns a readable stream of the poster JPEG.

function downloadImage(show, callback) {
    var filename = show.title + + " " + show.year + ".jpg";
    var path = "./images/" + filename;
    omdb.poster(show)
        .pipe(fs.createWriteStream(path))
        .on('error', function(err) {
            console.log("Download Omdb image err: " + err + " for " + show.title + " " + show.year);
            callback(err, null);
        })
        .on('close', function() {
            callback(null, path);
        });

}

function getOmdbInfo(show, callback) {
    omdb.get(show, true, function(err, movie) {
        if(err) {
            console.log("err:" + show.title + " " + show.year);
            callback(err, null);
        }
        if(!movie) {
            console.log("No OMDB info results for: " + show.title + " " + show.year);
            callback('Movie not found!', null);
        } else {
            callback(null, movie);
        }
    });
}

Error:

\node_modules\needle\lib\needle.js:81
      throw new TypeError('URL must be a string, not ' + uri);
            ^
TypeError: URL must be a string, not null
    at Object.Needle.request (\node
_modules\omdb\node_modules\needle\lib\needle.js:81:13)
    at Object.exports.(anonymous function) [as get] (\node_modules\omdb\node_modules\needle\lib\needle.js:425:19)
    at \node_modules\omdb\index.js:251:26
    at \node_modules\omdb\index.js:198:13
    at done (\node_modules\omdb\node_modules\needle\lib\needle.js:234:9)
    at PassThrough.<anonymous> (\node_modules\needle\lib\needle.js:363:11)
    at PassThrough.emit (events.js:129:20)
    at _stream_readable.js:908:16
    at process._tickCallback (node.js:355:11)
2
  • Could you please specify the show variable? Commented Nov 2, 2015 at 20:43
  • var show = {title: title, year: year}; example {title: "Fargo", year: 2004} Commented Nov 2, 2015 at 20:49

2 Answers 2

2

The problem arises because I catch the order after trying to pipe the file. By changing this:

omdb.poster(show)
        .pipe(fs.createWriteStream(path))
        .on('error', function(err) {
            console.log("Download Omdb image err: " + err + " for " + show.title + " " + show.year);
            callback(err, null);
        })
        .on('close', function() {
            callback(null, path);
        });

To this:

omdb.poster(show)
        .on('error', function(err) {
            console.log("Download OMDB image err: " + err + " for " + show.title + " " + show.year);
            callback(err, null);
        })
        .pipe(fs.createWriteStream(path))
        .on('close', function() {
            callback(null, path);
        });

The error is catched.

Sign up to request clarification or add additional context in comments.

Comments

0

Looking at this part of the omdb lib:

module.exports.poster = function (show) {
    var out = new stream.PassThrough(),
        req;

    module.exports.get(show, false, function (err, res) {
        if (err) {
            out.emit('error', err);
        } else if (!res) {
            out.emit('error', new Error('Movie not found'));
        } else {
            req = needle.get(res.poster);

            req.on('error', function (err) {
                out.emit('error', err);
            });

            req.pipe(out);
        }
    });

an educated guess is that the internal module.exports.get method passes an invalid url to the internal .get() method (I assume that res.poster does not exist). To be entirely sure - please test only the getOmdbInfo for the given movie - my tests returned no movie object for the 'Fargo' example.

3 Comments

You are right in that res.poster did not exist for the movie I attempted. The Fargo example was made up, the actual movie was made in 1996. But this is not the cause of my problems. I will post a solution
Caught me there with that fake year. Still, with the correct year your code works (at least on my mashine).
Yes, it happens with movies that exists on Imdb, but does not have a poster (example: imdb.com/title/tt3741316)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.