Jump to content
McKay Development

Recommended Posts

Posted

Hey,

 

I'm currently rewriting my bots due to all those new goodies which been developed in the last year (shoutouts to McKay and everyone working on these).

 

Currently debugging everything and saw that calling JSON.stringify on pollData returns undefined. Had a look at the original pollData and dug a little into the JSON.stringify manual. 

 

The manual's saying, that the method will return undefined if a part of the data is a function. Always thought that it would simply omit the function. (tested pre submitting: yep, everything I tried resulted in omitting the Function when calling stringify on the object).

 

Either way, Im at a loss here. 

 

Here's a Screenshot of the pollData (this is pre stringifying and right at the beginning of the pollData): ehy3PFK.png

 

and here's my event handler:

prototype._onPollData = function onPollDataCallback(data) {

    var that = this;
    
    try{
        var write = JSON.stringify(data);
    }catch (e){
        console.log(e);  //pls lemme find some
    }
    
    console.log(util.inspect(data, false, null));

    fs.writeFile('./bots/pollData/' + that.botName + '.json', JSON.stringify(data), function(err) {
        if (err){
            console.log(err);
        }
        return;
    });
};

I guess that I simply am screwing up somewhere and am just to tunneled to see it but wanted to make sure, if that [Function] really belongs there. 

 

Cheers

Posted

You probably attached a function to the poll data somewhere else in your code. That taints the entire object and makes it unserializable.

 

Look around for somewhere where you're attaching a function to pollData.

Posted

Yeah you're right. The problem was loading the existing pollData on start. 

 

On my other server (different project, manager version 1.18.1. The one with the problem just got a full update on all modules) I'm initially loading the pollData in a try/catch function if omitted by the constructor.

this.pollData = this.options.pollData || function() {
        try {
            JSON.parse(fs.readFileSync('./bots/pollData/' + this.botName + '.txt'));
        } catch (e) {
            fs.writeFileSync('./bots/pollData/' + this.botName + '.txt', '');
        }
    };

Which works over there. Since I C+P the whole Bot Object initialization I didn't look into this at all. This loads the file correctly on my production but not on the fully updated one. Passing this as pollData to the manager initialization puts the value as [Function]. Therefore on next poll, the data gets cloned by your manager and the real pollData gets attached, resulting in the messup.

 

As said in OP, too tunelled on the wrong part of the code. Thread can be closed.

 

Thanks for pointing me in the right direction =) 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...