I’m trying to build a simple python script that will extract some data from failed workflows such as the reason for the failure, etc.
To test it, I have a workflow that simply executes this:
if (true) throw ApplicationFailure.newNonRetryableFailure("ERROR", "dehk2");
However, when I try to dump the ExecutionHistory of this workflow, the stack trace is not “valid” json.
{
"EventId":5,
"EventTime":"2022-08-28 12":"34":44.829213835 +0000 UTC,
"EventType":"WorkflowExecutionFailed",
"Version":0,
"TaskId":59768879,
"Attributes":{
"WorkflowExecutionFailedEventAttributes":{
"Failure":{
"Message":"ERROR",
"Source":"JavaSDK",
"StackTrace":"io.temporal.failure.ApplicationFailure.newNonRetryableFailureWithCause(ApplicationFailure.java":"127)
io.temporal.failure.ApplicationFailure.newNonRetryableFailure(ApplicationFailure.java":"108)
com.saifxhatem.temporal.workflows.impl.WorkflowImpl.workflowMethod(WorkflowImpl.java":"46)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java":"62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java":"43)
java.lang.reflect.Method.invoke(Method.java":"498)
io.temporal.internal.sync.POJOWorkflowImplementationFactory$POJOWorkflowImplementation$RootWorkflowInboundCallsInterceptor.execute(POJOWorkflowImplementationFactory.java":"321)
io.temporal.internal.sync.POJOWorkflowImplementationFactory$POJOWorkflowImplementation.execute(POJOWorkflowImplementationFactory.java":"295)
io.temporal.internal.sync.WorkflowExecuteRunnable.run(WorkflowExecuteRunnable.java":"53)
io.temporal.internal.sync.SyncWorkflow.lambda$start$0(SyncWorkflow.java":"131)
io.temporal.internal.sync.CancellationScopeImpl.run(CancellationScopeImpl.java":"101)
io.temporal.internal.sync.WorkflowThreadImpl$RunnableWrapper.run(WorkflowThreadImpl.java":"110)
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java":"511)
java.util.concurrent.FutureTask.run(FutureTask.java":"266)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java":"1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java":"624)
java.lang.Thread.run(Thread.java":748),
"FailureInfo":{
"ApplicationFailureInfo":{
"Type":dehk2,
"NonRetryable":true
}
}
},
"RetryState":"RetryPolicyNotSet",
"WorkflowTaskCompletedEventId":4
}
}
}
Any attempts to parse it in python will throw an error because of the stacktrace line.
Interestingly enough, if I write it to a file, the file gets some \n
thrown in there, so it turns into valid json.
However, the machine that will execute the script will not be the machine where tctl runs, so I do not want to deal with the hassle of moving files, so I would prefer to read it in memory.
Is there any way to get valid json from tctl show?