func icon indicating copy to clipboard operation
func copied to clipboard

Return of void does not work for node function

Open astelmashenko opened this issue 1 year ago • 6 comments

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?

astelmashenko avatar May 31 '24 07:05 astelmashenko

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 avatar Jun 11 '24 06:06 lkingland

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[bot] avatar Sep 10 '24 01:09 github-actions[bot]

/remove-lifecycle stale

astelmashenko avatar Sep 10 '24 06:09 astelmashenko

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[bot] avatar Dec 10 '24 01:12 github-actions[bot]

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[bot] avatar Mar 11 '25 01:03 github-actions[bot]

/remove-lifecycle stale

astelmashenko avatar Mar 11 '25 09:03 astelmashenko

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[bot] avatar Jun 11 '25 01:06 github-actions[bot]