Failing a workflow and returning Data

Hi,

I have a scenario where I’m failing a workflow - due to an error in activity. When a workflow fails, the result returned is as follows:

{
  "type": "workflowExecutionFailedEventAttributes",
  "failure": {
    "message": "activity error",
    "source": "GoSDK",
    "stackTrace": "",
    "cause": {
      "message": "activity error",
      "source": "GoSDK",
      "stackTrace": "",
      "cause": null,
      "applicationFailureInfo": {
        "type": "",
        "nonRetryable": false,
        "details": null
      }
    },
    "activityFailureInfo": {
      "scheduledEventId": "17",
      "startedEventId": "18",
      "identity": "2570@XXX",
      "activityType": {
        "name": "ActivityFailedError"
      },
      "activityId": "17",
      "retryState": "MaximumAttemptsReached"
    }
  },
  "retryState": "MaximumAttemptsReached",
  "workflowTaskCompletedEventId": "22",
  "newExecutionRunId": ""
}

Any data that I was keeping track of as part of the workflow that I would return is lost. Is there a way to also ensure that any data returned is also part of the workflow result?

Thanks,
Jay.

Is there a way to also ensure that any data returned is also part of the workflow result?

If I understand the question correctly, you could expose query handlers for this info. You can query a completed / failed execution up to the set namespace retention period.

Thanks @tihomir. So will look into that.

However, just trying to understand reason why if there is an error, we cannot still return data with the error? It would be nice to see the data along with error reason in the UI.

While Go allows returning multiple results, the Temporal allows either result or failure as it needs to work across SDKs in multiple languages. You can return data embedded in the error (by returning an ApplicationFailure), but you cannot return both result and failure simultaneously.

Thanks for the explanation @maxim @tihomir.