sdk-go icon indicating copy to clipboard operation
sdk-go copied to clipboard

GetWorkflowError() does not yield stack trace for a panic

Open modernplumbing opened this issue 3 years ago • 1 comments

In a test like the following

type UnitTestSuite struct {
	suite.Suite # From github.com/stretchr/testify/suite | v1.7.0
	testsuite.WorkflowTestSuite # From go.temporal.io/sdk/testsuite | v1.12.0
	workflowEnvironment *testsuite.TestWorkflowEnvironment 
}

func (s *UnitTestSuite) Test_MyWorkflow() {
	s.workflowEnvironment.ExecuteWorkflow(MyWorkflow(), "test_success")
	s.NoError(s.workflowEnvironment.GetWorkflowError())
}

I would get output like the following:

--- FAIL: TestUnitTestSuite (0.01s)
    --- FAIL: TestUnitTestSuite/Test_MyWorkflow (0.00s)
        myTestFile_test.go:84:  
        Error Trace:    myTestFile_test.go:84
        Error:          Received unexpected error:
                   workflow execution error (type: MyWorkflowType, workflowID: default-test-workflow-id, runID: default-test-run-id): runtime error: invalid memory address or nil pointer dereference

The way to print the stack trace is by doing the following s.workflowEnvironment.GetWorkflowError().(*temporal.WorkflowExecutionError).Unwrap().(*temporal.PanicError).StackTrace() which is undocumented and took a lot of searching the repo for potential solutions.

Describe the solution you'd like Something like

func (e *PanicError) StackTrace() string

but for Workflow errors instead of just Activity errors would be great. s.workflowEnvironment.GetWorkflowError().(*temporal.WorkflowExecutionError).Unwrap().(*temporal.PanicError).StackTrace() is not great UX.

modernplumbing avatar Dec 27 '21 21:12 modernplumbing

Can you use errors.As instead, e.g.:

var panicErr *temporal.PanicError
if errors.As(err, &panicErr) {
  fmt.Printf("Got panic error, trace: %v", panicErr.StackTrace())
}

cretz avatar Jan 03 '22 14:01 cretz

Can you use errors.As instead, e.g.:

var panicErr *temporal.PanicError
if errors.As(err, &panicErr) {
  fmt.Printf("Got panic error, trace: %v", panicErr.StackTrace())
}

For me , it works. Thanks a lot!

var panicErr *temporal.PanicError
if errors.As(s.env.GetWorkflowError(), &panicErr) {
        fmt.Printf("Got panic error, trace: %v", panicErr.StackTrace())
}

BruceShenC avatar Feb 24 '23 01:02 BruceShenC