RangeError: Maximum call stack size exceeded pm2


#1

only after build and pm2 running

0|StudioKl | Unhandled rejection Error: Your card was declined. Your request was in test mode, but used a non test card. For a list of valid test cards, visit: https://stripe.com/docs/testing.
0|StudioKl |     at Constructor._Error (/home/project/bundle/programs/server/npm/node_modules/stripe/lib/Error.js:12:17)
0|StudioKl |     at Constructor (/home/project/bundle/programs/server/npm/node_modules/stripe/lib/utils.js:124:13)
0|StudioKl |     at new Constructor (/home/project/bundle/programs/server/npm/node_modules/stripe/lib/utils.js:124:13)
0|StudioKl |     at Function.StripeError.generate (/home/project/bundle/programs/server/npm/node_modules/stripe/lib/Error.js:55:14)
0|StudioKl |     at IncomingMessage.<anonymous> (/home/project/bundle/programs/server/npm/node_modules/stripe/lib/StripeResource.js:170:39)
0|StudioKl |     at emitNone (events.js:111:20)
0|StudioKl |     at IncomingMessage.emit (events.js:208:7)
0|StudioKl |     at endReadableNT (_stream_readable.js:1056:12)
0|StudioKl |     at _combinedTickCallback (internal/process/next_tick.js:138:11)
0|StudioKl |     at process._tickDomainCallback (internal/process/next_tick.js:218:9)
0|StudioKl | (node:31826) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 31): RangeError: Maximum call stack size exceeded
0|StudioKl | (node:31826) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 32): RangeError: Maximum call stack size exceeded
0|StudioKl | TypeError: Cannot read property 'filter' of undefined
0|StudioKl |     at bookingToConfirmFunc (imports/startup/server/startup.js:194:29)
0|StudioKl |     at imports/startup/server/startup.js:148:9
0|StudioKl |     at Array.forEach (<anonymous>)
0|StudioKl |     at imports/startup/server/startup.js:147:14
PM2        | App [StudioKlub] with id [0] and pid [31826], exited with code [1] via signal [SIGINT]
PM2        | Starting execution sequence in -fork mode- for app name:StudioKlub id:0
PM2        | App name:StudioKlub id:0 online
0|StudioKl | You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
0|StudioKl | RangeError: Maximum call stack size exceeded
0|StudioKl |     at Object.EJSON._isCustomType (packages/ejson/ejson.js:223:23)
0|StudioKl |     at Object.EJSON.clone (packages/ejson/ejson.js:588:13)
0|StudioKl |     at packages/ejson/ejson.js:595:22
0|StudioKl |     at Array.forEach (<anonymous>)
0|StudioKl |     at Object.EJSON.clone (packages/ejson/ejson.js:594:18)
0|StudioKl |     at packages/ejson/ejson.js:595:22
0|StudioKl |     at Array.forEach (<anonymous>)
0|StudioKl |     at Object.EJSON.clone (packages/ejson/ejson.js:594:18)
0|StudioKl |     at packages/ejson/ejson.js:595:22
0|StudioKl |     at Array.forEach (<anonymous>)
0|StudioKl |     at Object.EJSON.clone (packages/ejson/ejson.js:594:18)
0|StudioKl |     at packages/ejson/ejson.js:595:22
0|StudioKl |     at Array.forEach (<anonymous>)
0|StudioKl |     at Object.EJSON.clone (packages/ejson/ejson.js:594:18)
0|StudioKl |     at packages/ejson/ejson.js:595:22

#3
import {
    Meteor
} from 'meteor/meteor';
import Fiber from 'fibers';
import Stripe from 'stripe';
import {
    Accounts
} from 'meteor/accounts-base';
import cron from 'node-cron';

const stripe = Stripe("sk_test_X++++++++NtEcaVU");
import {
    getAllBookings,
    getAllBookingsConfirmed,
    cancelBooking,
    getBookingsPast,
    getBookingsToConfirm,
    getBookingsToReConfirm
} from "../../api/bookings/methods.js"

import {
    getRatingByStudio
} from "../../api/ratings/methods.js"

import {
    getStudioForViewForall
} from "../../api/studios/methods.js"

import {
    addNotification
} from "../../api/notifications/methods.js"
import moment from 'moment';

cron.schedule('*/30 * * * *', function () {
    console.log("30 Min");
    console.log('running a task every two minutes');

    Fiber(function () {
        var bookings = getAllBookings.call();

        if (bookings && bookings.length > 0) {
            bookings.forEach(element => {
                try {
                    cancelBook(element)
                } catch (error) {
                    console.log("error bookings",error);
                }
            });
        }

        var bookingsConf = getAllBookingsConfirmed.call();
        if (bookingsConf && bookingsConf.length > 0) {
            bookingsConf.forEach(element => {
                try {
                cancelBook2(element)
            } catch (error) {
                console.log("error bookingsConf",error);
            }
            });
        }

        var allUser = Meteor.users.find();
        allUser.forEach(element => {
            if (element.profile && element.profile.accountId) {
                try {
                    stripe.balance.retrieve({
                        stripe_account: element.profile.accountId
                    }, function (err, balance) {
                        if (!err) {
                            // console.log("thebalance",balance);
                            Fiber(function () {
                                updateUser(element._id, balance)
                            }).run();
                        } else {}
                    }); 
                } catch (error) {
                    console.log("error allUser",error);
                }
            }

        });

    }).run();

});

function updateUser(id, balance) {
    Meteor.users.update({
        _id: id
    }, {
        $set: {
            "profile.balance": balance.available[0].amount,
            "profile.balanceComing": balance.pending[0].amount
        }
    })
}

function cancelBook2(element) {
    var dateNow = moment();

    var theDate = element.dateSession.split("/")
    theDate = theDate[1] + "/" + theDate[0] + "/" + theDate[2];
    var newDate = Date.parse(theDate)
    var hours = Math.abs(dateNow - moment(theDate)) / 36e5;

    console.log("hours hours222", hours);
    if (hours >= 48) {
        cancelBooking.call({
            bookId: element._id,
            userId: "NONE",
        })
    }
}


function cancelBook(element) {
    var dateNow = moment();
    if (element.modified) {
        var hours = Math.abs(dateNow - moment(element.modifiedAt)) / 36e5;
        console.log("hours hoursmodifiedAt", hours);
        if (hours >= 72) {
            Meteor.call("cancelBook", {
                chargeId: element.charge,
                bookId: element._id,
                userId: element.createdBy
            }, function (err, succ) {
                if (err) {
                    console.log("cancelBook Auto err", err);
                }

            })
        }
    } else {
        var hours = Math.abs(dateNow - moment(element.createdAt)) / 36e5;
        console.log("hours hours", hours);
        if (hours >= 72) {
            Meteor.call("cancelBook", {
                chargeId: element.charge,
                bookId: element._id,
                userId: element.createdBy
            }, function (err, succ) {
                if (err) {
                    console.log("cancelBook Auto err", err);
                }

            })
        }
    }
}

cron.schedule('*/360 * * * *', function () {
    Fiber(function () {
    console.log("360 Min, 6h");

    var allUsers = Meteor.users.find({
        "profile.removed": false
    }).fetch();

    allUsers.forEach(element => {
        try {
            bookingToConfirmFunc(element)
        } catch (error) {
            console.log("error bookingToConfirmFunc", error);
        }
    })

    allUsers.forEach(element => {
        try {
            ratingAStudioRememb(element)     
        } catch (error) {
            console.log("error ratingAStudioRememb", error);
        }
        
    })
}).run();


});

function ratingAStudioRememb(element) {
    var bookings = getBookingsPast.call({
        userId: element._id
    })

    if(bookings){
        bookings.filter(function (element) {
            return element !== undefined;
        })
        bookings.forEach(element2 => {
            ratingAStudioRememb2(element, element2)
        })
    }

    
}

function ratingAStudioRememb2(element, element2) {
    var theStudio = getStudioForViewForall.call({
        studioId: element2.studio
    }, function (err) {
        console.log("res err startup", err);
    })

    var theRate = getRatingByStudio.call({
        to: element2.studio,
        userId: element._id
    }, function (err) {
        console.log("res err startup", err);
    })

    if (!theRate) {
        if (element.profile.notifRating) {
            addNotificationNotifRating(element,theStudio);
        }

    }
}

function bookingToConfirmFunc(element) {
    var bookingsToConfirm = getBookingsToConfirm.call({
        userId: element._id
    }, function (err) {
        console.log("bookingsToConfirm err startup", err);
    })
    if(bookingsToConfirm){
        bookingsToConfirm.filter(function (element) {
            return element !== undefined;
        })
        var bookingsToReConfirm = getBookingsToReConfirm.call({
            userId: element._id
        }, function (err) {
            console.log("bookingsToConfirm err startup", err);
        })
        if(bookingsToReConfirm){
            bookingsToReConfirm.filter(function (element) {
                return element !== undefined;
            })
            if (bookingsToReConfirm.length > 0) {
                if (element.profile.notifRemConf) {
                    addNotificationBookingsToConfirm(element)
                }
            }
        
            if (bookingsToConfirm.length > 0) {
                if (element.profile.notifRemConf) {
                    addNotificationBookingsToConfirm(element)
                }
            }
        }
        
    }
   
}

function addNotificationBookingsToConfirm(element) {
    addNotification.call({
        title: "Studios",
        description: "Vous avez oublié de confirmer une réservation",
        icon: element.profile.photoProfile,
        userid: element._id,
        url: "/dashboard/bookings/toconfirm"
    }, function (err) {
        console.log("res err startup", err);
    })
}

function addNotificationNotifRating(element,theStudio) {
    addNotification.call({
        title: "Réservation",
        description: "Vous avez oublié d'évaluer un studio après une réservation [" + theStudio.title + "]",
        icon: theStudio.photos[0],
        userid: element._id,
        url: "/studio/ratings/" + theStudio.uri
    }, function (err) {
        console.log("res err startup", err);
    })
}

#4

no answer ???


#5

The error is telling you that you are using a test key, but you are not using one of the designated test card numbers.


#6

#7

I m talking about those problems

31826) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 31): RangeError: Maximum call stack size exceeded
0|StudioKl | (node:31826) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 32): RangeError: Maximum call stack size exceeded
0|StudioKl | TypeError: Cannot read property 'filter' of undefined
0|StudioKl |     at bookingToConfirmFunc (imports/startup/server/startup.js:194:29)
0|StudioKl |     at imports/startup/server/startup.js:148:9
0|StudioKl |     at Array.forEach (<anonymous>)
0|StudioKl |     at imports/startup/server/startup.js:147:14
PM2        | App [StudioKlub] with id [0] and pid [31826], exited with code [1] via signal [SIGINT]
PM2        | Starting execution sequence in -fork mode- for app name:StudioKlub id:0
PM2        | App name:StudioKlub id:0 online
0|StudioKl | You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
0|StudioKl | RangeError: Maximum call stack size exceeded
0|StudioKl |     at Object.EJSON._isCustomType (packages/ejson/ejson.js:223:23)
0|StudioKl |     at Object.EJSON.clone (packages/ejson/ejson.js:588:13)
0|StudioKl |     at packages/ejson/ejson.js:595:22
0|StudioKl |     at Array.forEach (<anonymous>)
0|StudioKl |     at Object.EJSON.clone (packages/ejson/ejson.js:594:18)
0|StudioKl |     at packages/ejson/ejson.js:595:22
0|StudioKl |     at Array.forEach (<anonymous>)
0|StudioKl |     at Object.EJSON.clone (packages/ejson/ejson.js:594:18)
0|StudioKl |     at packages/ejson/ejson.js:595:22
0|StudioKl |     at Array.forEach (<anonymous>)
0|StudioKl |     at Object.EJSON.clone (packages/ejson/ejson.js:594:18)
0|StudioKl |     at packages/ejson/ejson.js:595:22
0|StudioKl |     at Array.forEach (<anonymous>)
0|StudioKl |     at Object.EJSON.clone (packages/ejson/ejson.js:594:18)
0|StudioKl |     at packages/ejson/ejson.js:595:22

RangeError: Maximum call stack size exceeded