learnyounode icon indicating copy to clipboard operation
learnyounode copied to clipboard

MAKE IT MODULAR: verification fails when fs.readdir receives encoding parameter

Open appleseedexm opened this issue 8 years ago • 5 comments

I've had the same issue like many where the verification of my script returned the following:

Your submission results compared to the expected:

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

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

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

ERROR: There was a problem printing the solution files: testing

I got this error although I've had returned the callback function in case of an error in fs.readdir(). So I've updated learnyounode and received the following error:

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  

  ✗  Your additional module file [DirFilterModule.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)  


     # FAIL  
     Your solution to MAKE IT MODULAR didn't pass. Try again!  

I was 100% sure my code was right and almost gave up until I thought about my fs.readdir line which is supposedly wrong:

fs.readdir(folderpath, 'utf8', function(err, files) { /* code */ })

fs.readdir() accepts an optional second parameter which could define the encoding of the returned filenames. If this is set, learnyounode thinks the on-error callback is not being returned.

Hope this helps.

appleseedexm avatar Jun 07 '16 22:06 appleseedexm

Yes, this is awful. Spent extra hour trying to understand what's wrong with this challenge. Apparently their error checking somehow connected to the file format.

leakvoid avatar Aug 03 '16 15:08 leakvoid

It will break also if you put it into an object. Very sad.

jaakkopaakkonen avatar Sep 14 '16 05:09 jaakkopaakkonen

Yeah this cost me quite some time.

Razpudding avatar Nov 24 '16 17:11 Razpudding

Same here! It cost me half an hour before I got here! (I've got this habit of reading a lot of issues on Github)

Thanks for sharing :)

IOAyman avatar Dec 05 '16 17:12 IOAyman

Same frustration. Thirty minutes to write the solution and over an hour to make the learnyoumode parser happy. Turns out if you add any text to the error you are passing back... if (err) return callMeBack("Error in fs.readdir; " + err) ...it will fail the verify step.

vbsql7 avatar May 19 '17 12:05 vbsql7