Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Functions] Response body after Timeout is mangled and non-informative #1459

Closed
caesarsol opened this issue Oct 21, 2020 · 1 comment · Fixed by #1460
Closed

[Functions] Response body after Timeout is mangled and non-informative #1459

caesarsol opened this issue Oct 21, 2020 · 1 comment · Fixed by #1460
Labels
area: command: dev area: functions type: bug code to address defects in shipped code

Comments

@caesarsol
Copy link
Contributor

caesarsol commented Oct 21, 2020

Describe the bug

The response of a Netlify Function incurring in timeout is �[91m◈�[39m Function invocation failed: [object Object] instead of a clear explanation of the timeout issue.

To Reproduce

Steps to reproduce the behavior:

  1. Create a function taking >10s to perform:
    async function handler(event, context, callback) {
      await new Promise((r) => setTimeout(r, 20_000))
      return callback(null, {})
    }
  2. Run netlify dev
  3. Call the associated endpoint
  4. Wait 10s (the default timeout)
  5. Response will be non-informative and malformatted:
    HTTP/1.1 500 Internal Server Error
    
    �[91m◈�[39m Function invocation failed: [object Object]
    

Configuration

  • netlify.toml:
     [build]
       functions = "./functions"
     
     [dev]
       framework = "create-react-app"
    
  • npx envinfo:
       System:
         OS: macOS 10.15.7
         CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
         Memory: 279.05 MB / 16.00 GB
         Shell: 5.7.1 - /bin/zsh
       Binaries:
         Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node
         Yarn: 1.16.0 - ~/.yarn/bin/yarn
         npm: 6.13.4 - ~/.nvm/versions/node/v12.16.1/bin/npm
    

Expected behavior

A more informative output.
Maybe in JSON format, or customizable by the user?

CLI Output

◈ Error during invocation: {
  errorMessage: 'Task timed out after 10.00 seconds',
  errorType: 'TimeoutError',
  stackTrace: [
    'new TimeoutError (.../node_modules/netlify-cli/node_modules/lambda-local/build/lib/utils.js:110:28)',
    'Context.<anonymous> (.../node_modules/netlify-cli/node_modules/lambda-local/build/lib/context.js:110:19)',
    'listOnTimeout (internal/timers.js:549:17)',
    'processTimers (internal/timers.js:492:7)'
  ],
  level: 'error',
  [Symbol(level)]: 'error',
  [Symbol(message)]: '{"errorMessage":"Task timed out after 10.00 seconds","errorType":"TimeoutError","stackTrace":["new TimeoutError (.../node_modules/netlify-cli/node_modules/lambda-local/build/lib/utils.js:110:28)","Context.<anonymous> (.../node_modules/netlify-cli/node_modules/lambda-local/build/lib/context.js:110:19)","listOnTimeout (internal/timers.js:549:17)","processTimers (internal/timers.js:492:7)"],"level":"error"}'
}

Additional context

This is what I've found:

  • the message Function invocation failed is created here:
    function handleErr(err, response) {
    response.statusCode = 500
    response.write(`${NETLIFYDEVERR} Function invocation failed: ` + err.toString())
    response.end()
    console.log(`${NETLIFYDEVERR} Error during invocation:`, err)
    }
  • it's prepended with a terminal-colored char for console output, but being not used in console this messes up the output with non utf-8 chars
  • the [object Object] is the result of an error.toString() on something which apparently inherits from Object
  • the TimeoutError is generated by lambda-local, but gets later translated into a plain Object here:
    https://github.com/ashiina/lambda-local/blob/develop/src/lib/context.ts#L181-L185

I am now going to write a quick PR to make the actual error appear in the HTTP body.

@caesarsol caesarsol added the type: bug code to address defects in shipped code label Oct 21, 2020
@caesarsol caesarsol changed the title Function response body after timeout is non informative [Functions] Response body after Timeout is mangled and non-informative Oct 21, 2020
@caesarsol
Copy link
Contributor Author

PR sent, let me know if I can further help.

caesarsol added a commit to caesarsol/netlify-cli that referenced this issue Oct 22, 2020
erezrokah pushed a commit to caesarsol/netlify-cli that referenced this issue Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: command: dev area: functions type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants