openwhisk-client-go icon indicating copy to clipboard operation
openwhisk-client-go copied to clipboard

wrong statusCode in case of application error in activation output

Open ShubhamGupta9582 opened this issue 5 years ago • 6 comments

Hi guys,

I am getting statusCode 0 in case of application error. It should be 1 in case of application error. I am returning 400 statusCode in my action's output but it is showing statusCode 0 in response map and in the root json also it is showing statusCode 0. you can see the output of wsk -i activation get activationId command in below screenshot. Screenshot from 2021-01-05 13-18-14

ShubhamGupta9582 avatar Jan 05 '21 07:01 ShubhamGupta9582

The status code you return for a web action is not the same as the status code that is generated by the system and part of the response object. The latter is explained here https://github.com/apache/openwhisk/blob/b00678d30604d0ffb45792fdcd4b61714cfffd1c/docs/actions.md#understanding-the-activation-record

Since your function's result is an error object, and the status string is application error you are correct the statusCode should be 1. That it's showing as 0 is actually a wsk CLI bug - the HTTP response is omitting this property and the wsk CLI is assuming it is 0.

You can see this by adding -v to the wsk command and looking at the HTTP response.

I have to check why the HTTP response is not include the status code though. EDIT: I did, see https://github.com/apache/openwhisk/issues/5039#issuecomment-754695275

rabbah avatar Jan 05 '21 14:01 rabbah

Yes, I was not saying that statusCode should be same with my statusCode. It just that if i return any error in my action then the statusCode should not be 0. if it is application error then it should be 1, if it is developer error then it should be 2 or if it is whisk error then it should be 3.

ShubhamGupta9582 avatar Jan 05 '21 14:01 ShubhamGupta9582

From: https://github.com/apache/openwhisk/blob/b00678d30604d0ffb45792fdcd4b61714cfffd1c/common/scala/src/main/scala/org/apache/openwhisk/core/entity/ActivationResult.scala#L36-L45

The statusCode is removed from the activation result. This is a CLI bug.

rabbah avatar Jan 05 '21 15:01 rabbah

https://github.com/apache/openwhisk-client-go/blob/49c58e00354d315ce82766c785c69193df0514e8/whisk/activation.go#L59

The Go serialization is assuming the field is present and when it is not it default to 0. It's a bug in that library (ugh https://github.com/apache/openwhisk-cli/issues/148).

rabbah avatar Jan 05 '21 15:01 rabbah

I'm curious, @ShubhamGupta9582 are you trying to modify the CLI to report the web action status code? What you ran into is clearly a bug that should be fixed in this Go client for OpenWhisk. Depending on what you might be doing, there may be easier solutions - feel free to reach out to me on the community Slack if you want to chat about it.

rabbah avatar Jan 05 '21 15:01 rabbah

No, I am not changing CLI. Sure, I'll connect with you on community Slack.

ShubhamGupta9582 avatar Jan 05 '21 15:01 ShubhamGupta9582