Skip to content

Commit

Permalink
Display Proper Error Message from Error Object
Browse files Browse the repository at this point in the history
- Parse and display error objects properly
  • Loading branch information
dubee authored and rabbah committed Oct 24, 2016
1 parent 60d025f commit 37e5857
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
13 changes: 13 additions & 0 deletions tests/dat/actions/asyncError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function main(params) {
var str = params.payload;

return whisk.invoke({
name: '!', // Invalid action name
parameters: {
payload: str
},
blocking: true
}).then(function (activation) {
return {};
});
}
11 changes: 11 additions & 0 deletions tests/src/system/basic/WskBasicTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@ class WskBasicTests
.stderr should include regex (""""error": "This error thrown on purpose by the action."""")
}

it should "create and invoke a blocking action resulting in an error response object" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
val name = "errorResponseObject"
assetHelper.withCleaner(wsk.action, name) {
(action, _) => action.create(name, Some(TestUtils.getTestActionFilename("asyncError.js")))
}

wsk.action.invoke(name, blocking = true, expectedExitCode = 246)
.stderr should include regex (""""error": "name '!' contains illegal characters \(.+\)"""")
}

it should "invoke a blocking action and get only the result" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
val name = "basicInvoke"
Expand Down
14 changes: 4 additions & 10 deletions tools/cli/go-whisk/whisk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,10 @@ func parseWhiskErrorResponse(resp *http.Response, data []byte, v interface{}) (*
err := json.Unmarshal(data, whiskErrorResponse)

// Determine if a whisk.error() response was received. Otherwise, the body contents are unknown (#6)
if err == nil && whiskErrorResponse.Response.Result.Error != nil {
Debug(DbgInfo, "Detected that a whisk.error(\"%s\") was returned\n", *whiskErrorResponse.Response.Result.Error)
if err == nil && whiskErrorResponse.Response.Status != nil {
Debug(DbgInfo, "Detected that a whisk.error(\"%s\") was returned\n", *whiskErrorResponse.Response.Status)
errMsg := wski18n.T("The following application error was received: {{.err}}",
map[string]interface{}{"err": *whiskErrorResponse.Response.Result.Error})
map[string]interface{}{"err": *whiskErrorResponse.Response.Status})
whiskErr := MakeWskError(errors.New(errMsg), resp.StatusCode - 256, NO_DISPLAY_MSG, NO_DISPLAY_USAGE,
NO_MSG_DISPLAYED, APPLICATION_ERR)
return parseSuccessResponse(resp, data, v), whiskErr
Expand Down Expand Up @@ -361,13 +361,7 @@ type WhiskErrorResponse struct {
}

type WhiskErrorResult struct {
Status string `json:"status"`
Success bool `json:"success"`
Result WhiskErrorMessage `json:"result"`
}

type WhiskErrorMessage struct {
Error *string `json:"error"`
Status *string `json:"status"`
}

func (r ErrorResponse) Error() string {
Expand Down

0 comments on commit 37e5857

Please sign in to comment.