Rishikant181 / Rettiwt-API

A CLI tool and an API for fetching data from Twitter for free!
https://rishikant181.github.io/Rettiwt-API/
MIT License
484 stars 46 forks source link

Maximum call stack size exceeded #629

Closed matgott closed 1 month ago

matgott commented 1 month ago
[Rettiwt-API] [2024-10-17T17:56:28.803Z] [AUTHORIZATION] {"authenticated":true}
[Rettiwt-API] [2024-10-17T17:56:28.803Z] [VALIDATE] {"target":"FETCH_ARGS"}    
[Rettiwt-API] [2024-10-17T17:56:28.805Z] [GET] {"target":"HTTPS_AGENT"}        
[Rettiwt-API] [2024-10-17T17:56:28.805Z] [GET] {"target":"USER_CREDENTIAL"}    
[Rettiwt-API] [2024-10-17T17:56:29.753Z] [DESERIALIZE] {"id":"1846972990321574260"}
F:\Proyectos\fetch-tweet\node_modules\rettiwt-api\dist\models\data\Tweet.js:22
        this.tweetBy = new User_1.User(tweet.core.user_results.result);
                       ^

RangeError: Maximum call stack size exceeded
    at new Tweet (F:\Proyectos\fetch-tweet\node_modules\rettiwt-api\dist\models\data\Tweet.js:22:24)
    at Tweet.getQuotedTweet (F:\Proyectos\fetch-tweet\node_modules\rettiwt-api\dist\models\data\Tweet.js:53:20)
    at new Tweet (F:\Proyectos\fetch-tweet\node_modules\rettiwt-api\dist\models\data\Tweet.js:25:28)
    at Tweet.getQuotedTweet (F:\Proyectos\fetch-tweet\node_modules\rettiwt-api\dist\models\data\Tweet.js:53:20)
    at new Tweet (F:\Proyectos\fetch-tweet\node_modules\rettiwt-api\dist\models\data\Tweet.js:25:28)
    at Tweet.getQuotedTweet (F:\Proyectos\fetch-tweet\node_modules\rettiwt-api\dist\models\data\Tweet.js:53:20)
    at new Tweet (F:\Proyectos\fetch-tweet\node_modules\rettiwt-api\dist\models\data\Tweet.js:25:28)
    at Tweet.getQuotedTweet (F:\Proyectos\fetch-tweet\node_modules\rettiwt-api\dist\models\data\Tweet.js:53:20)
    at new Tweet (F:\Proyectos\fetch-tweet\node_modules\rettiwt-api\dist\models\data\Tweet.js:25:28)
    at Tweet.getQuotedTweet (F:\Proyectos\fetch-tweet\node_modules\rettiwt-api\dist\models\data\Tweet.js:53:20)

Class Tweet is called with a tweet:

new Tweet(tweet)

When it tries to get the quoted tweet it does: this.quoted = this.getQuotedTweet(tweet); (same tweet object reference)

Inside getQuotedTweet it does:

    Tweet.prototype.getQuotedTweet = function (tweet) {
        // If tweet with limited visibility
        if (tweet.quoted_status_result &&
            Object.entries(tweet.quoted_status_result).length &&
            tweet.quoted_status_result.result.__typename == 'TweetWithVisibilityResults') {
            return new Tweet(tweet.quoted_status_result.result.tweet);
        }
        // If normal tweet
        else if (tweet.quoted_status_result && Object.entries(tweet.quoted_status_result).length) {
            return new Tweet(tweet);
        }
        // Else, skip
        else {
            // Logging
            LogService_1.LogService.log(Logging_1.ELogActions.WARNING, {
                action: Logging_1.ELogActions.DESERIALIZE,
                message: 'Quoted tweet not found, skipping',
            });
            return undefined;
        }
    }

If it is a normal tweet it calls again new Tweet(tweet) here tweet is the same object as at the begginning. So it is calling new Tweet again with the same tweet object that's going to call getQuotedTweet and it'll call new Tweet again and again.

Instead of return new Tweet(tweet); shouldn't it be return new Tweet(tweet.result); (idk)

Also this is happening for a Tweet that has +300 quotes/retweets.

Rishikant181 commented 1 month ago

Man, that a very noob mistake by me :(

image

Here, it should have been return new Tweet(tweet.quoted_status_result.result as ITweet)

Thanks for pointing it out.

matgott commented 1 month ago

Man, that a very noob mistake by me :(

image

Here, it should have been return new Tweet(tweet.quoted_status_result.result)

Thanks for pointing it out.

Haha it may happen! Also I ran my code for a different user and I didn't get the error. Then I try with this one and it failed, not easy to catch.

Rishikant181 commented 1 month ago

I wonder why while testing it with a tweet with quotes, that error wasn't thrown. But this tweet did (and thankfully so). Will have to check that too.

Rishikant181 commented 1 month ago

Please upgrade to v4.1.3. Issue has been fixed.