diff --git a/service/history/chasm_engine.go b/service/history/chasm_engine.go index a182fc2dbc1..39a25890c30 100644 --- a/service/history/chasm_engine.go +++ b/service/history/chasm_engine.go @@ -621,6 +621,10 @@ func (e *ChasmEngine) getExecutionLease( executionLease.GetReleaseFn()(nil) err = staleReferenceErr } + var notFound *serviceerror.NotFound + if errors.As(err, ¬Found) { + err = serviceerror.NewNotFound("execution not found") + } return shardContext, executionLease, err } diff --git a/service/history/chasm_engine_test.go b/service/history/chasm_engine_test.go index 5fc94b69f04..0a394f110d9 100644 --- a/service/history/chasm_engine_test.go +++ b/service/history/chasm_engine_test.go @@ -625,6 +625,31 @@ func (s *chasmEngineSuite) TestReadComponent_Success() { s.NoError(err) } +// TestReadComponent_NotFound tests that ReadComponent returns an appropriate NotFound error message. +func (s *chasmEngineSuite) TestReadComponent_NotFound() { + s.mockExecutionManager.EXPECT().GetWorkflowExecution(gomock.Any(), gomock.Any()). + Return(nil, serviceerror.NewNotFound("this error message will not be returned by ReadComponent")).Times(1) + + err := s.engine.ReadComponent( + context.Background(), + chasm.NewComponentRef[*testComponent]( + chasm.ExecutionKey{ + NamespaceID: string(tests.NamespaceID), + BusinessID: "non-existent-execution", + RunID: "11111111-2222-3333-4444-555555555555", + }, + ), + func(ctx chasm.Context, component chasm.Component) error { + s.Fail("readFn should not be called") + return nil + }, + ) + s.Error(err) + var notFound *serviceerror.NotFound + s.ErrorAs(err, ¬Found) + s.Equal("execution not found", notFound.Message) +} + func (s *chasmEngineSuite) buildPersistenceMutableState( key chasm.ExecutionKey, componentState proto.Message,