dherault / dherault/serverless-offline

Error processing numeric data type

Open
#1,556 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
5.3k
Forks
811
Avg merge
2d 4h
Merged PRs (30d)
3

Description

## Bug Report

**Current Behavior**

I'm running a fetch function using Prisma against a table with `numeric` data types. The fetch executes well, but the `numeric` data type seems to be causing an error to throw in node_modules/serverless-offline/src/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js in the following code `port.postMessage(result)`. Running the code sample below and selecting only non-numeric fields causes no issue, but including one or more numeric field in the select causes the following error to throw:

image

**Sample Code**

```ts
export const fetchVitals = async (request: fetchVitalsParams): Promise<{} | false> => {

try {

const { patientId, select: selectString } = request.queryStringParameters;
let select: Prisma.patient_vitalSelect | undefined;

try {
select = selectString ? JSON.parse(selectString) : undefined;
} catch (error) {
throw new Error(`unable to process select: ${selectString}`);
}

const vitalsRecord = await prismaClinical.patient_vital.findUnique({
where: {
patient_id: parseInt(patientId, 10)
},
select
});

return vitalsRecord || false;

} catch (error) {

console.error('an error occurred while fetching vitals');
return false;
}
};
```

- file: serverless.yml

```yaml
service: my-service-name

frameworkVersion: '3'

plugins:
- serverless-webpack
- serverless-offline

package:
individually: true

provider:
name: aws
runtime: nodejs16.x
stage: '${opt:stage, "local"}'

custom:
serverless-offline:
lambdaPort: 4500
httpPort: 4000

functions:
vitals-get:
handler: src/functions/database-requests/clinical/observations.fetchVitals
events:
- httpApi:
method: GET
path: /database-requests/clinical/vitals
```

**Expected behavior/code**

I would expect execution to work without throwing this error

**Environment**

- `serverless` version: 3.22.0
- `serverless-offline` version: 9.2.3
- `node.js` version: 16.16.0
- `OS`: macOS 12.4

**Possible Solution**

Unfortunately I haven't been able to find a fix, however I'd guess that the issue stems from shallow cloning the `result` in `port.postMessage(result)`. I am happy to help reproduce the issue and work through it if needed.

**Additional context/Screenshots**

Screenshot of execution paused right before a message that doesn't throw the error is processed:

image

Screenshot of execution paused right before a message the does throw the error is processed:

image

Contributor guide

Open the contributing guide

Research direction

Start in serverless-offline/src/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js at port.postMessage(result), then reproduce the fetch described in the issue using serverless.yml and a Prisma query that selects a numeric field. Compare it with a query selecting only non-numeric fields; done means numeric results are processed without the worker message throwing.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.