Welcome to the Linux Foundation Forum!

id === 'c060' ch 5 labs-1 model.js

andrewpartrickmiller
edited January 2021 in LFW212 Class Forum

Hi in chapter 5 labs-1 model.js in the function named read

there is an if clause that looks like this

        if (id === 'c060') {             
          setImmediate(() => cb(Error('unknown')))  
        }  

The entire function looks like this

      function read (id, cb) {           
        if (id === 'c060') {             
          setImmediate(() => cb(Error('unknown')))  
        }                                
        if (!(db.hasOwnProperty(id))) {  
          const err = Error('not found') 
          err.code = 'E_NOT_FOUND'       
          setImmediate(() => cb(err))    
          return 
        }
        setImmediate(() => cb(null, db[id]))
      }

What does 'c060' mean, the error message says 'unknown'. I was trying to trigger that error message, How do I trigger that error message?

Thanks!

Answers

  • this is there for the validation code to trigger, it's simulating an unknown error using a known ID. There's no need to try to trigger this yourself, but more be aware that unexpected errors need to be handled.

Categories

Upcoming Training