learnyounode icon indicating copy to clipboard operation
learnyounode copied to clipboard

MAKE IT MODULAR - Verify Error

Open jmz527 opened this issue 8 years ago • 7 comments

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_it_modular.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)

jmz527 avatar Jan 28 '17 00:01 jmz527

+1

hanhdt avatar Feb 09 '17 04:02 hanhdt

+1

igor-klymenok avatar Feb 25 '17 06:02 igor-klymenok

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.

itsjtwright avatar Mar 01 '17 06:03 itsjtwright

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

dmwelch avatar Mar 24 '17 18:03 dmwelch

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 avatar Apr 07 '17 17:04 jmz527

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!

jmz527 avatar Apr 07 '17 17:04 jmz527

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.

AnshulMalik avatar Jun 22 '17 16:06 AnshulMalik