-2

I'm calling the function getKeywords from another function and got an Unrecheable code detected section and don't understand why. Any help?

var env         = require('dotenv').config();
var request     = require('request')
var getKeywords = function(){
request.get('URI', //URI IS CORRECT IN MY CODE
function(err, httpResponse, body){
    if(err){ //UNREACHABLE CODE DETECTED
        console.error("request.post Error:", err);  
        return false;  
    } //UNREACHABLE CODE DETECTED
    else{
        console.log('Im here');
        return JSON.parse(httpResponse.body).keywords;
    }
 });
}

module.export = getKeywords;

Here is the calling code.

  var getKeywords  = require('./getKeywords.js');
  var keywords     = new getKeywords();
  var env          = require('dotenv').config();
  var difflib      = require('difflib');
  var postMention  = require('./postMention.js');

 var detection   = function(obj, i){
       var keyword = keywords[i];
            var mentionObject = {
                //some json
            //postMention(mentionObject);
        }

 }     
  module.exports = detection;
  • 3
    what tool did you use that identified the unreachable code? – zzzzBov Apr 01 '16 at 18:00
  • Whatever tool, I think it is mistaken here. – Thomas R. Koll Apr 01 '16 at 18:03
  • I'm using visual studio code on ubuntu 14.04. The thing is that I console.log() it and it doesn't output anything. – Angel G Garcia Almodovar Apr 01 '16 at 18:06
  • 1
    You have some other issue that you are not disclosing to us in your real code (a mismatched string or some other error) or this is a false error in your tools. There's nothing wrong with the code you show us, exactly as it is shown. – jfriend00 Apr 01 '16 at 18:07
  • After loading this module, are you actually calling the module constructor function that is named `getKeywords()` here? If you put a `console.log()` as the first line of `getKeywords()`, does it get called? Can you show us the calling code? – jfriend00 Apr 01 '16 at 18:13
  • Added the calling code in the text above – Angel G Garcia Almodovar Apr 01 '16 at 18:37
  • I should add that even if your `console.log()` statements were being hit, you would not get a return value from `getKeywords()` because the result is asynchronous. You can see why by reading this: http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call/14220323#14220323 – jfriend00 Apr 01 '16 at 21:59
  • I found my error. In my getKeywords function i had module.export... it should be module.exports.. i was missing an s – Angel G Garcia Almodovar Apr 05 '16 at 07:14

1 Answers1

-2

Some tools have the ability to analyze every call to your function. It may be possible that all the places in your code that call the function you never set err parameter to true.

fbidwell
  • 32
  • 2