0

I've written this module for Kassy to search anime via the HummingBird API. The module loads fine and even the help command /help humming returns the appropriate help message. But I can't get it to respond to search queries

The console just displays

An unhandled error occurred. Start as debug for details.

and continues listening to the next message. I have tried running the console in debug mode (as mentioned in the Kassy docs) but the console displays the same message. I have tried installing the module with KPM but same results.

These are the two files in the directory named humming inside the modules directory

humming.js

console.debug('line 10');
var request = require.safe('request');

/*
* Paths
*/
var HUMMINGBIRD_HOST = "hummingbird.me/api/v1";
var HUMMINGBIRD_SEARCH = "/search/anime/";

exports.match = function(text, commandPrefix) {
    console.debug('line 23');
    return text.startsWith(commandPrefix + 'humming');
};

/*
    Method that provides help strings for use with this module.
*/
exports.help = function(commandPrefix) {
    return [[commandPrefix + 'humming <query>','Searches Anime or Manga when you are too lazy to make a few clicks']];
};

/*
    The main entry point of the module. This will be called by Kassy whenever the match function
    above returns true.
*/
exports.run = function(api, event) {
        var query = event.body.substr(8);

        console.debug('line 40');

        search(query, function(error, response){
            // Callback calls the parser if no errors were registered
            if(error !== null){
                api.sendMessage(parse(response), event.thread_id);
            } else{
                console.debug(error);
            }
        });
};

function parse(query){
    // testing
    return JSON.stringify(query);
    // return 'parser reached';
}

/**
 * Retrieves information about an anime as a JSON object.
 *
 * query:       string to search
 * callback:    takes the error, and data
 */
function search(query, callback) {
    request.get({
        url: "https://" + HUMMINGBIRD_HOST + 
             HUMMINGBIRD_SEARCH + "?query=" + query,
        headers: {
                 "Content-Type": "application/x-www-form-urlencoded"
             }
    }, function(err, res, body) {

        console.debug('line 73');

        if(err) {
            if(res) {
                callback("Request error: " + err + ", " + res.statusCode, body);
            }
            else {
                callback("Connection error: not connected to internet", body);
            }
        }
        else {
            callback(null, body);
        }
    });
}

kassy.json

{
  "name": "humming",
  "version": 2.0,
  "startup": "humming.js"
}

You will notice some calls to the debugger log but those are never shown in debug mode, so I'm not sure whether the module isn't being executed at all or if my debugging is faulty. This is the startup command I used to enable debugging

node debug main.js facebook test

I have tried renaming the module as well to test, manga, anime, etc. assuming there might be ambiguity in the system but nothing changed.

I'm unsure about my implementation of request.get method as I'm new to Javascript and have followed the method syntax from this GitHub project

You can find my module's files on Github as well And find out more about Kassy here

Paras
  • 253
  • 3
  • 16

1 Answers1

1

I had a quick look and could not replicate the unhandled error, but if you change the block of code in your search callback to

if(!error){
  api.sendMessage(response, event.thread_id);
} else{
  console.debug(error);
}

This will print the raw response to the output.

If the exception occurs again you can send the following command

/issue "title" "description" full

This will dump a lot of configuration data to an issue on the Kassy github.

Awarua
  • 36
  • 1
  • 3
  • Ohhh is `error` a boolean as well? or is JS treating variables differently than what I'm expecting? (I C#, not in JS though haha) – Paras Feb 11 '16 at 23:55
  • 1
    Js treats things a bit differently this sort of explains it https://stackoverflow.com/questions/4361585/javascript-how-to-test-if-a-variable-is-not-null – Awarua Feb 12 '16 at 01:17