【问题标题】:SendGrid sgMail.send error using coffeescript meteor. Works fine as pure JSSendGrid sgMail.send 使用咖啡脚本流星的错误。作为纯 JS 工作正常
【发布时间】:2019-07-25 02:52:23
【问题描述】:

当我在 Coffee 中编码时,sgMail.send(msg) 调用会产生错误。如果我离开的是嵌入式 js,它可以正常工作。

这是错误:

I20190305-07:32:50.195(-8)? Exception while invoking method 'sendEmail' RangeError: Maximum call stack size exceeded
I20190305-07:32:50.196(-8)?     at Array.forEach (<anonymous>)
I20190305-07:32:50.196(-8)?     at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
I20190305-07:32:50.196(-8)?     at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
I20190305-07:32:50.196(-8)?     at Array.forEach (<anonymous>)
I20190305-07:32:50.196(-8)?     at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
I20190305-07:32:50.196(-8)?     at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
I20190305-07:32:50.196(-8)?     at Array.forEach (<anonymous>)
I20190305-07:32:50.196(-8)?     at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
I20190305-07:32:50.196(-8)?     at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
I20190305-07:32:50.196(-8)?     at Array.forEach (<anonymous>)
I20190305-07:32:50.196(-8)?     at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
I20190305-07:32:50.196(-8)?     at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
I20190305-07:32:50.197(-8)?     at Array.forEach (<anonymous>)
I20190305-07:32:50.197(-8)?     at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
I20190305-07:32:50.197(-8)?     at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
I20190305-07:32:50.197(-8)?     at Array.forEach (<anonymous>)
I20190305-07:32:50.197(-8)?  => awaited here:
I20190305-07:32:50.197(-8)?     at Promise.await (/Users/paulpedrazzi/.meteor/packages/promise/.0.11.2.a0r1i6.m5ai8++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/meteor-promise/promise_server.js:60:12)
I20190305-07:32:50.197(-8)?     at Server.apply (packages/ddp-server/livedata_server.js:1634:14)
I20190305-07:32:50.197(-8)?     at Server.call (packages/ddp-server/livedata_server.js:1603:17)
I20190305-07:32:50.197(-8)?     at MethodInvocation.sendEmail (server/main.coffee:77:12)
I20190305-07:32:50.197(-8)?     at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1767:12)
I20190305-07:32:50.197(-8)?     at DDP._CurrentMethodInvocation.withValue (packages/ddp-server/livedata_server.js:719:19)
I20190305-07:32:50.198(-8)?     at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1304:12)
I20190305-07:32:50.198(-8)?     at DDPServer._CurrentWriteFence.withValue (packages/ddp-server/livedata_server.js:717:46)
I20190305-07:32:50.198(-8)?     at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1304:12)
I20190305-07:32:50.198(-8)?     at Promise (packages/ddp-server/livedata_server.js:715:46)
I20190305-07:32:50.198(-8)?     at new Promise (<anonymous>)
I20190305-07:32:50.198(-8)?     at Session.method (packages/ddp-server/livedata_server.js:689:23)
I20190305-07:32:50.198(-8)?     at packages/ddp-server/livedata_server.js:559:43

【问题讨论】:

    标签: meteor coffeescript sendgrid


    【解决方案1】:

    我不认为consts 是你的问题。在 Coffeescript 中,您可以删除它们。在 JS 中删除 const 不会破坏以前运行的代码(尽管添加它们可以)。这是您转换为咖啡脚本的示例:

    sgMail = require('@sendgrid/mail')
    sgMail.setApiKey(process.env.SENDGRID_API_KEY)
    msg = 
      to: 'test@example.com'
      from: 'test@example.com'
      subject: 'Sending with SendGrid is Fun'
      text: 'and easy to do anywhere, even with Node.js'
      html: '<strong>and easy to do anywhere, even with Node.js</strong>'
    
    sgMail.send(msg)
    

    Here you can see the javascript it is converted to

    错误看起来像是一个无限循环或递归函数调用。

    如果您将 JS 代码转换为 Coffeescript,请检查您的缩进,因为 Coffeescript 将其用于块而不是大括号。

    如果您能确定错误来自哪几行,您可以发布该代码以及调用它的位置。

    【讨论】:

    • 感谢您的关注。我添加了您的代码并且有相同的错误(在上面添加)。所以我的咖啡版本还可以。从字面上看,我所做的一切都是在服务器上调用该函数。很奇怪。
    • 好点。我假设是 const,但也许是别的东西。
    • @ppedrazzi 错误来自 EJSON 库(由流星使用),可能试图对循环对象进行操作。这是question with the same error message。它可能会有所帮助,但错误消息无法告诉我们错误来自何处,因此我建议您使用 console.logs 填写您的代码,直到您大致弄清楚它失败的位置。
    • 好的,所以我发现它与结束 sgMail.send(msg) 上的流星方法调用有关,因为如果我在最后一行添加一个 console.log 语句,一切正常.
    猜你喜欢
    • 2014-05-22
    • 2018-01-25
    • 2013-03-27
    • 2017-01-07
    • 1970-01-01
    • 2012-02-08
    • 2013-02-15
    • 1970-01-01
    • 2023-03-23
    相关资源
    最近更新 更多