I am in macos and scheduled a node script as a cronjob. I am saving the logs of the cronjob to a file. When the script is executed from shell manually with same command I've in cronjob, it executes successfully but it gives error from cronjob.
The script has used snoowrap
to request to get top posts from the reddit. I think it's where the error comes from. The error is:
RangeError: Maximum call stack size exceeded
at /Users/kiro/Documents/learns/myproj/node_modules/snoowrap/dist/objects/Listing.js:231:21
at tryCatcher (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/promise.js:729:18)
at _drainQueueStep (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (node:internal/timers:466:21)
node:internal/process/promises:265
triggerUncaughtException(err, true /* fromPromise */);
The command i'm using in crontab is
~/Documents/learns/myproj/job.sh >> ~/Documents/learns/myproj/cron.log 2>&1
where job.sh has
~/.nvm/versions/node/v16.14.0/bin/node ~/Documents/learns/myproj/build/index
This is the part of code that gives error
await this.redditClient
.getSubreddit(subreddit)
.getTop({ time: "day", limit: 400, count: 400 });
I also tried by passing --max-stack-size 32000
but still gives same error.
What can be the reason for this and how can I solve it?