Graphcool / graphcool-framework

Apache License 2.0
1.78k stars 130 forks source link

"error": "Function returned invalid status code: 0. Raw body: empty.last" #453

Open marktani opened 6 years ago

marktani commented 6 years ago

Issue by Boid-John Tuesday Jan 09, 2018 at 07:52 GMT Originally opened as https://github.com/graphcool/prisma/issues/1550


Current behavior 2018-01-09T07:42:50.148Z 46ms FAILURE { "error": "Function returned invalid status code: 0. Raw body: empty.last" } Reproduction

const fromEvent = require('graphcool-lib').fromEvent
const er = (err) => {
  console.log(err.message)
  return { error: err.message }
}
const mUpdateToken = `
mutation($tokenId:ID! $balance:Float!){
  updateToken(
    id:$tokenId
    balance:$balance
  ){
    id
    balance
  }
}
`

const updateTokenBalance = async (api,tokenId,balance) => {
  return (await api.request(mUpdateToken,{tokenId,balance})
  .catch(er))
}

const addMinted = (a,el) =>{
  if (el.transactionType==="MINT"){
    return a + parseFloat(el.ammount)
  }
}

const init = async function(event){
    const graphcool = fromEvent(event)
    const api = graphcool.api('simple/v1')
    // console.log(event.data.TokenTransaction.node)
    var token = event.data.TokenTransaction.node.token
    console.log(token)
    var minted = token.transactions.reduce(addMinted,0)
    console.log('found Total Minted',minted)
    balance = minted
    var finished = (await updateTokenBalance(api,token.id,balance).catch(er))
    console.log(finished)
    return {data:{success:true}}
}

module.exports = init
subscription {
  TokenTransaction(filter: {
    mutation_in: [CREATED]
  }) {
    node{
      token{
        id
        transactions{
          transactionType
          ammount
        }
      }
    }
  }
}
  updateWalletBalance:
    type: subscription
    query: ./src/TokenTransactionCreated.graphql
    handler:
      code:
        src: src/updateWalletBalance.js

Expected behavior? Function should work the same remote vs deployed and return useful errors

When function is run with invoke-local:

    { id: 'cjbvq7gb459b10106sor9hvdv',
      transactions:
       [ { transactionType: 'MINT', ammount: 106.84382089966455 },
         { transactionType: 'MINT', ammount: 5.065958362701446 },
         { transactionType: 'MINT', ammount: 0.029171372180809393 },
         { transactionType: 'MINT', ammount: 3.132041730654067 },
         { transactionType: 'MINT', ammount: 3.9368225204850718 } ] }
  console.log src/updateWalletBalance.js:68
    found Total Minted 119.00781488568595

{ updateToken: { id: 'cjbvq7gb459b10106sor9hvdv', balance: 119.00781488568595 } }

Result:

{
  "data": {
    "success": true
  }
}
marktani commented 6 years ago

Comment by marktani Wednesday Jan 10, 2018 at 10:22 GMT


Can you try replacing

const er = (err) => {
  console.log(err.message)
  return { error: err.message }
}

with

const er = (err) => {
  return { error: "error" }
}

and see if that helps? 🙂

marktani commented 6 years ago

Comment by thauvette Saturday Jan 13, 2018 at 13:42 GMT


I was getting the same error. I made the changes suggested by @marktani but now the function doesn't run at all.

marktani commented 6 years ago

Comment by Boid-John Saturday Jan 13, 2018 at 16:05 GMT


Same. I moved to a different platform.

On Sat, Jan 13, 2018 at 7:42 AM, Matt Thauvette notifications@github.com wrote:

I was getting the same error. I made the suggested changes but now the function doesn't run at all.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/graphcool/graphcool/issues/1550#issuecomment-357436291, or mute the thread https://github.com/notifications/unsubscribe-auth/Ac0uR1nisUnOodsvLh7MxDPGPJmuLlWvks5tKLLdgaJpZM4RXb9Q .

-- John Heeter Founder & CTO @ Boid.com

marktani commented 6 years ago

Comment by omatrot Monday Jan 15, 2018 at 16:17 GMT


I have the exact same problem with a typescript function of my own. I started from a mutation template. In its simple form it just awaited a timeout and returned some data. I added code that is working in a test program outside graphcool framework. I know that is is partially working because I send emails and I receive them. This is not tied to the console calls because I have none. What can I do to help pinpoint the issue ?

marktani commented 6 years ago

Comment by Boid-John Monday Jan 15, 2018 at 16:25 GMT


Graphcool is abandoning managed functions in their latest version, disappointing, as managed functions are part of the "Graphcool Framework" announced in October. I ran into many issue with their implementation so I moved to using the cli at serverless.com.

On Mon, Jan 15, 2018 at 10:17 AM, Olivier MATROT notifications@github.com wrote:

I have the exact same problem with a typescript function of my own. I started from a mutation template. In its simple form it just awaited a timeout and returned some data. I added code that is working in a test program outside graphcool framework. I know that is is partially working because I send emails and I receive them. This is not tied to the console calls because I have none. What can I do to help pinpoint the issue ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/graphcool/graphcool/issues/1550#issuecomment-357727791, or mute the thread https://github.com/notifications/unsubscribe-auth/Ac0uRwRNV1zAwuKXN9qwctgvaXNtnKH3ks5tK3oFgaJpZM4RXb9Q .

-- John Heeter Founder & CTO @ Boid.com

marktani commented 6 years ago

Comment by marktani Monday Jan 15, 2018 at 16:33 GMT


Hey, thanks a lot for your feedback @Boid-John, @thauvette and @omatrot 🙂 I am still looking into reproducing this and finding a workaround so we can work on a fix.

@omatrot you could try to do a "binary search" on your function, to find out which specific change introduces the error message. That would be super helpful 👍

marktani commented 6 years ago

Comment by omatrot Tuesday Jan 16, 2018 at 15:16 GMT


I'll do that because Graphcool is awesome. Stay tuned.

marktani commented 6 years ago

Comment by omatrot Tuesday Jan 16, 2018 at 17:44 GMT


I think I've found it. I'm using Es6 Promise (@typescript -- 2.1.1 lib.es6.d.ts Promise Description) in the function that fails whereas the simple test function is using es2015 Promise (lib.es2015.symbol.wellknown.d.ts)

marktani commented 6 years ago

Comment by omatrot Wednesday Jan 17, 2018 at 10:55 GMT


Well I'm probably wrong about my first analysis. The function is running fine up to the point of returning data. I'm using loggly to replace console.log and it shows me that everything is fine, no exception is thrown in my code...

marktani commented 6 years ago

Comment by omatrot Wednesday Jan 17, 2018 at 13:25 GMT


In a local cluster deployment it works perfectly fine. Could you tell me how get access to the shared cluster logs ? May be this could help.

marktani commented 6 years ago

Comment by marktani Thursday Jan 18, 2018 at 13:56 GMT


Hey @omatrot thanks for digging into this!

Given that it works locally but not remotely makes me believe that it might be an issue in the way graphcool deploy bundles the local functions together before deploying it to AWS Lambda. My current assumption is that something causes an error when then executing the function in AWS Lambda, and that error is not correctly caught by the functions engine.

Do you see anything suspicious about the produced bundle, in the case of this error occuring? You can enabled debug output by setting the env variable DEBUG to "*". In fish:

set -xg DEBUG "*"
marktani commented 6 years ago

Comment by omatrot Thursday Jan 18, 2018 at 14:11 GMT


@marktani I do not see something suspicious per se, but I notice that you're using ts-builder to transpile the typescript code. Does it take into account the tsconfig.json file ? Another question : Do you use the same node.js version on the local docker engine versus the lambda engine on AWS ? I have some experience with AWS typescript lambda and node.js is version 6.10.

marktani commented 6 years ago

Comment by omatrot Thursday Jan 18, 2018 at 16:14 GMT


My playground output is the following:

{
  "data": {
    "addMeeting": null
  },
  "errors": [
    {
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "addMeeting"
      ],
      "code": 5000,
      "message": "A function returned an unhandled error. Please check the logs for executionId 'us-west-2:simple:cjckp2902lyfb01804649umew'",
      "requestId": "us-west-2:simple:cjckp2902lyfb01804649umew"
    }
  ]
}

@marktani Have you the ability to check those logs ?

marktani commented 6 years ago

Comment by omatrot Saturday Jan 20, 2018 at 07:12 GMT


@marktani can you ping me on Slack ? I have material to reproduce the issue. I'd like to send you the code by email for privacy. Thanks in advance.

lastmjs commented 6 years ago

I'm also getting this error

senorcodecat commented 6 years ago

Also getting this error

janvogt commented 6 years ago

I'm also getting this error for multiple functions after an (theoretically) unrelated deploy. Also sometimes it works.

juanpprieto commented 6 years ago

Sadly, I've also ran into this issue. Seems sporadic too.

Not sure it's related, but is there a default Timeout in CLI functions?

Kisepro commented 6 years ago

I have the same problem with the template googleAuthentication if I add a log for the variable "googleToken" for exemple

async function getGoogleUser(googleToken: string): Promise<GoogleUser> {
  console.log("getGoogle")
  //  console.log("googleToken", googleToken) // log googleToken make it crashes wherever I try to log it
  const endpoint = "https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=" + googleToken;
  const data = await fetch(endpoint)
    .then(response => response.json())
dohomi commented 6 years ago

I'm seeing this error as well on signup user function. Any idea what could cause this?

Kisepro commented 6 years ago

No news ?

anaibol commented 6 years ago

Having also this issue with aws-sdk s3 upload.

grimunit commented 6 years ago

Was getting this when I used requires instead of imports