workshopper / learnyounode

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

Make It Modular - results match but won't pass, no errors #378

Closed richdefies closed 9 years ago

richdefies commented 9 years ago

Can anyone help? I've looked at issues here and even though there are a lot of reports around this exercise, none seem to match the problem. I'm getting no errors from the verify program other than "error cleaning up: testing" and the actual/expected results match.

Thanks!

-> modules $ learnyounode verify main.js

Your submission results compared to the expected:

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

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

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

Error cleaning up: testing

main.js:

var directory = process.argv[2];
var extension = process.argv[3];

var filterfiles = require('./filteredls');

filterfiles(directory, extension, function(err, data) {
    data.forEach(function(file){
        console.log(file);
    });
});

filteredls.js:

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

module.exports = function(directory, fileext, callback){

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

        if (err) {
            callback(err);
        }

        var data = list.map(function (file) {
            if ( path.extname(file) === "."+fileext ) {
                return file;
            }
        });

        data = data.filter(function(item){
            if ( item ) return item;
        });     

        callback(null, data);

    });

};
onedeadear commented 9 years ago

Try adding the following in your main.js:

if (err)
    console.log(err);
richdefies commented 9 years ago

Tried that -- still not working. I attended a workshop last night focused on learnyounode and the mentor there said that with all the tests passing green, he determined it was a bug on the Workshopper side and to move on to the other challenges. Happy to help debug if any other suggestions!

One note is I'm on Node 5.0...

martinheidegger commented 9 years ago

The error occurs with rimraf. I am not quite sure why it occurs (obviously removing the folder seems to result in an error) but i just publish a fix that ignores this particular error and published a new learnyounode workshopper. Would you mind testing it with that?

richdefies commented 9 years ago

@martinheidegger Aha, that did it. So when I put in your fix and ran the verification, it returned:

 ✗ Your additional module file [filteredls.js] does not appear to pass back an error received from `fs.readdir()`.  
   Use the following idiomatic Node.js pattern inside your callback to `fs.readdir()`:  
     if (err)  
       return callback(err)  
 ✓ Additional module file handles errors properly  

So, I noticed my module file had callback(err) and not return callback(err). I made that change and now the challenge completed. All of them down!

Thanks.