in openwhisk/runHandler.go [158:203]
func (ap *ActionProxy) doServerModeRun(bodyRequest *runRequest) (RemoteRunResponse, int, error) {
Debug("Executing run request in server mode")
body, status, err := prepareRemoteRunBody(ap, bodyRequest)
if err != nil {
return RemoteRunResponse{}, status, err
}
// execute the action
response, err := ap.theExecutor.Interact(body)
// check for early termination
if err != nil {
Debug("WARNING! Command exited")
ap.theExecutor = nil
return RemoteRunResponse{}, http.StatusBadRequest, fmt.Errorf("command exited")
}
DebugLimit("received (remote): ", response, 120)
// check if the answer is an object map or array
if ok := isJsonObjOrArray(response); !ok {
return RemoteRunResponse{}, http.StatusBadGateway, fmt.Errorf("the action did not return a dictionary or array")
}
// Get the stdout and stderr from the executor
outStr, err := os.ReadFile(ap.outFile.Name())
if err != nil {
outStr = []byte(fmt.Sprintf("Error reading stdout: %v", err))
}
errStr, err := os.ReadFile(ap.errFile.Name())
if err != nil {
errStr = []byte(fmt.Sprintf("Error reading stderr: %v", err))
}
// clear out the files
os.Truncate(ap.outFile.Name(), 0)
os.Truncate(ap.errFile.Name(), 0)
// create the response struct
remoteResponse := RemoteRunResponse{
Response: response,
Out: string(outStr),
Err: string(errStr),
}
return remoteResponse, 0, nil
}