workshopper / learnyounode

Learn You The Node.js For Much Win! An intro to Node.js via a set of self-guided workshops.
Other
7.29k stars 1.83k forks source link

MAKE IT MODULAR - Verify Error #500

Open jmz527 opened 7 years ago

jmz527 commented 7 years ago

I'm getting an error when verifying the "Make It Modular" exercise. One of the processors seems to be missing a call function.

Here's my "make_it_modular.js" file:

var my_module = require('./my_module');

my_module(process.argv[2], process.argv[3], function(err, arg) {
    if (err) {
        console.log(err)
    } else {
        console.log(arg);
    }
});

Here's the "my_module.js" file:

var fs = require('fs');
var path = require('path');

module.exports = function(dirName, fileExt, callback) {

    fs.readdir(dirName, function (err, list) {

        if (err) return callback(err);

        list.forEach(function (file) {  
            if (path.extname(file) === '.' + fileExt)
            return callback(file);
        })
    })
}

And here's the output when I run _learnyounode verify make_itmodular.js:

# LEARN YOU THE NODE.JS FOR MUCH WIN!

## MAKE IT MODULAR (Exercise 6 of 13)

Your submission results compared to the expected:

                 ACTUAL                                 EXPECTED
────────────────────────────────────────────────────────────────────────────────

   "CHANGELOG.md"                      ==    "CHANGELOG.md"
   "LICENCE.md"                        ==    "LICENCE.md"
   "README.md"                         ==    "README.md"
   ""                                  ==    ""

────────────────────────────────────────────────────────────────────────────────

 ✓

 Submission results match expected

 ✓

 Additional module file exports a single function

 ✓

 Additional module file exports a function that takes 3 arguments

 ✓

 Additional module file handles errors properly

 ✓

 Additional module file handles callback argument

/usr/local/lib/node_modules/learnyounode/node_modules/workshopper-exercise/exercise.js:188
    processors[i].call(self, mode, function (err, pass) {
                 ^

TypeError: Cannot read property 'call' of undefined
    at next (/usr/local/lib/node_modules/learnyounode/node_modules/workshopper-exercise/exercise.js:188:18)
    at /usr/local/lib/node_modules/learnyounode/node_modules/workshopper-exercise/exercise.js:195:7
    at callback (/usr/local/lib/node_modules/learnyounode/exercises/make_it_modular/verify.js:26:15)
    at modFileError (/usr/local/lib/node_modules/learnyounode/exercises/make_it_modular/verify.js:31:5)
    at /usr/local/lib/node_modules/learnyounode/exercises/make_it_modular/verify.js:118:18
    at /Users/jamesrutledge/Desktop/nodeschool/learnyounode/my_module.js:12:11
    at Array.forEach (native)
    at /Users/jamesrutledge/Desktop/nodeschool/learnyounode/my_module.js:10:8
    at FSReqWrap.oncomplete (fs.js:123:15)
hanhdt commented 7 years ago

+1

igor-klymenok commented 7 years ago

+1

itsjtwright commented 7 years ago

So your running a for loop on the wrong side of the code. You need the arg you return to be an array and use the forEach loop on the other side. Does that make sense?

Only one thing can be returned and you are trying to return something for every item in the array.

dmwelch commented 7 years ago

Would be helpful if the verify would provide a hint instead of this cryptic error 🙏

jmz527 commented 7 years ago

Yup, that makes sense. Don't put your callback function within a loop - the module should only make one callback. I got rid of that loop, added a filter to my module file, a console log loop to my main file, and I got it up & working.

jmz527 commented 7 years ago

Here's the part of the directions that tripped me up:

You must write a module file to do most of the work.

If it's too much trouble to work in a human-friendly error, then maybe just revise the lesson a bit or add in an explicit warning.

Thanks for the great workshop!

AnshulMalik commented 7 years ago

As far as I can see, the problem statement tells you that you need to pass an array to callback and call the callback exactly pass.

How can we make it more friendly?

Feel free to open a PR.