serverless-offline icon indicating copy to clipboard operation
serverless-offline copied to clipboard

DataCloneError

Open BhangalePratik opened this issue 2 years ago • 9 comments

Bug Report

Current Behavior

I started the API gateway locally through the command "serverless offline". It exposed all the endpoints when I hit them. I got the following error : Error: DataCloneError: async (event_, context = {}) => { const event = cleanUpEvent(event_, options);

Sample Code

  • file: serverless.yml
service: recipe
frameworkVersion: '3'

provider:
  name: aws
  runtime: nodejs14.x
  iam:
    role:
      statements:
        - Effect: 'Allow'
          Action:
            - "lambda:InvokeFunction"
            - "lambda:InvokeAsync"
          Resource: "*"

functions:
  main:
    handler: main.handler
    name: main
    events:
      - http:
          path: /healthCheck
          method: get
      - http:
          path: /setWebhook
          method: get
      - http:
          path: /botMessage
          method: post
  getAPIResultStoreInDatabase:
    handler: fetch-api-response.handler
    name: getAPIResultStoreInDatabase

plugins:
  - serverless-offline
  • file: handler.js

``exports.handler = async () => { const token = await fetchBotToken(); const url = #url // const localUrl = 'https://cfba-2a02-6b61-8173-0-f462-a49f-4fd8-313b.eu.ngrok.io/botMessage' const app = express();

// parse the updates to JSON app.use(express.json());

app.get('/healthCheck', (req, res) => { res.status(200).send('API Gateway URL is working!!!') })

app.get('/setWebhook', async (req, res) => {

const options = {
  method: 'GET',
  url: `https://api.telegram.org/bot${token}/setWebhook?url=${url}`,
};
const apiResponse = await axios.request(options)
const result = apiResponse ?.data
return res.status(200).json(result)

})

// We are receiving updates at the route below! app.post(/botMessage, async (req, res) => {

const responseArray = await responseHandler(req.body.message.text)
const promiseResponse = await Promise.all(responseArray.map((response) => {
  const options = {
    method: 'POST',
    url: `https://api.telegram.org/bot${token}/sendMessage`,
    data: {
      "chat_id": req.body.message.chat.id,
      "text": response,
      "parse_mode": "HTML"
    }
  };
  return axios.request(options)
}))

return res.status(200).json(promiseResponse.map((response) => {
  return {
    status: response.status,
    text: response.data.result.text
  }
}))

});

return serverless(app);

}


**Expected behavior/code**

The expected behavior is that it will expose all the endpoints and I can hit on them and they will work.

**Environment**
- "serverless-http": "^2.7.0"
- "serverless-offline": "^12.0.3"
- `node.js` version: [e.g. v16.13.0]
- `OS`: Windows 10

BhangalePratik avatar Dec 27 '22 12:12 BhangalePratik

I am also facing a similar issue, not entirely sure what this means Tabby_MNkvdbb68i

shierro avatar Feb 22 '23 13:02 shierro

Rolling back serverless-offline to version 8.8.1 solved this issue for me. It seems like it might be related to failed (403) http requests within application code in my case.

stocks29 avatar Mar 14 '23 00:03 stocks29

Same issue for me after update from version 7 to version 12

kirylvarykau avatar Mar 15 '23 10:03 kirylvarykau

I wanted to fallback to using version 8 below, but my runtime isn't supported :(

To add more info that might help, this error happened when I introduced the usage of npm package form-data to send some file into openai audio transcription service

shierro avatar May 03 '23 06:05 shierro

it seems like it! this happen because there's an error within the application, and serverless-offline wasn't able to process the error because of DataCloneError, or there's a function inside the error object/context.. need to probably try/catch, or something to overcome the debugging issue, or handle it here somehow

shierro avatar May 03 '23 11:05 shierro

I'm also getting DataCloneError when running serverless-offline. × Uncaught exception Environment: linux, node 14.21.3, framework 3.31.0 (local), plugin 6.2.3, SDK 4.3.2 Docs: docs.serverless.com Support: forum.serverless.com Bugs: github.com/serverless/serverless/issues Error: DataCloneError: function transformRequest(data, headers) { const contentType = headers.getContentType() || ""; const ha...... } could not be cloned. at MessagePort. (file:///usr/src/app/node_modules/serverless-offline/src/lambda/handler-runner/worker thread-runner/workerThreadHelper.js:26:10) at processTicksAndRejections (internal/process/task_queues.js:95:5)

Nicopa avatar Jun 01 '23 12:06 Nicopa

it seems like it! this happen because there's an error within the application, and serverless-offline wasn't able to process the error because of DataCloneError, or there's a function inside the error object/context.. need to probably try/catch, or something to overcome the debugging issue, or handle it here somehow

Yes, my function was throwing an error on runtime.

Nicopa avatar Jun 01 '23 13:06 Nicopa

any update here? I've just run into this issue as well

node v16.x

Packages:

  "devDependencies": {
    "cfn-resolver-lib": "1.1.7",
    "chai": "^4.3.7",
    "mocha": "^10.2.0",
    "serverless": "^3.33.0",
    "serverless-appsync-plugin": "^1.13.0",
    "serverless-appsync-simulator": "^0.19.6",
    "serverless-cloudfront-invalidate": "^1.12.2",
    "serverless-dynamodb-local": "^0.2.40",
    "serverless-offline": "^12.0.4",
    "serverless-offline-direct-lambda": "^0.0.1",
    "serverless-plugin-common-excludes": "^4.0.0",
    "serverless-prune-plugin": "^2.0.1",
    "serverless-s3-deploy": "^0.10.1"
  }

try/catch wrapped handler and this is still the case

full stack trace:

✖ Uncaught exception
Environment: darwin, node 16.9.1, framework 3.33.0 (local), plugin 6.2.3, SDK 4.3.2
Credentials: Local, "default" profile
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
DataCloneError: function PopulateDocuments(settings, callback) {
    if (typeof settings === "function") {
        callback = s...<omitted>...
} could not be cloned.
    at MessagePort.<anonymous> (file:///Users/usr/repo/node_modules/serverless-offline/src/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js:30:8)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

EDIT: Downgrading to serverless-offline ^8.0.0 solved the issue with node 16.x

liam-ot avatar Jul 05 '23 10:07 liam-ot

image Still Getting this error . Node.js Version 18.19.1 serverless-offline 13.3.3

gem-madhav avatar Mar 05 '24 10:03 gem-madhav