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

Return of void does not work for node function #2336

Open
astelmashenko opened this issue May 31, 2024 · 3 comments
Open

Return of void does not work for node function #2336

astelmashenko opened this issue May 31, 2024 · 3 comments
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@astelmashenko
Copy link

Function template: void
Language: node

There is possible return types in the docs https://github.com/knative/func/tree/main/templates/node/cloudevents#handle-signature:

type CloudEventFunctionReturn = Promise<CloudEvent> | CloudEvent | HTTPFunctionReturn;
type HTTPFunctionReturn = Promise<StructuredReturn> | StructuredReturn | ResponseBody | void;

When I try to return nothing:

const handle = async (context, event) => {
  // YOUR CODE HERE
  context.log.info("context", context);
  context.log.info("event", event);
};

I get error

curl -X POST -d '{"name": "Tiger", "customerId": "0123456789"}' \
  -H'Content-type: application/json' \
  -H'Ce-id: 1' \
  -H'Ce-source: cloud-event-example' \
  -H'Ce-type: dev.knative.example' \
  -H'Ce-specversion: 1.0' \
  http://localhost:8080
Cannot read properties of undefined (reading 'constructor')

How do I return void?

@lkingland
Copy link
Member

lkingland commented Jun 11, 2024

Hello @astelmashenko,

Our Node.js middleware is under active development, and unfortunately that has resulted in a few of our return types being only partially implemented.

An updated version of the Node.js middleware is in progress, but for the short term I would recommend returning an empty StructuredReturn or ResponseBody in leau of a proper void.

We can leave this issue open to ensure that the upcoming middleware release tests the void return is working correctly.

Thanks for opening the issue, and sorry for the inconvenience

@lkingland lkingland added the kind/bug Categorizes issue or PR as related to a bug. label Jun 11, 2024
Copy link
Contributor

This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Reopen the issue with /reopen. Mark the issue as
fresh by adding the comment /remove-lifecycle stale.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 10, 2024
@astelmashenko
Copy link
Author

/remove-lifecycle stale

@knative-prow knative-prow bot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
Status: No status
Development

No branches or pull requests

2 participants