Skip to content

Commit 3c51318

Browse files
authored
Add more softassert.UnexpectedInternalErr (#8456)
## What changed? Replace a few `serviceerror.NewInternal` with `softassert.UnexpectedInternalErr`. ## Why? Catch these issues in CICD and other testing. ## How did you test it? - [ ] built - [ ] run locally and tested manually - [x] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s)
1 parent de46aa8 commit 3c51318

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

chasm/tree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ func (n *Node) serialize() error {
658658
case *persistencespb.ChasmNodeMetadata_PointerAttributes:
659659
return n.serializePointerNode()
660660
default:
661-
return serviceerror.NewInternal("unknown node type")
661+
return softassert.UnexpectedInternalErr(n.logger, "unknown node type", nil)
662662
}
663663
}
664664

service/history/api/startworkflow/api.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"go.temporal.io/server/common/persistence"
2222
"go.temporal.io/server/common/persistence/visibility/manager"
2323
"go.temporal.io/server/common/primitives"
24+
"go.temporal.io/server/common/softassert"
2425
"go.temporal.io/server/common/tasktoken"
2526
"go.temporal.io/server/service/history/api"
2627
"go.temporal.io/server/service/history/consts"
@@ -252,7 +253,11 @@ func (s *Starter) prepareNewWorkflow(workflowID string) (*creationParams, error)
252253

253254
workflowTaskInfo := mutableState.GetStartedWorkflowTask()
254255
if s.requestEagerStart() && workflowTaskInfo == nil {
255-
return nil, serviceerror.NewInternal("unexpected error: mutable state did not have a started workflow task")
256+
return nil, softassert.UnexpectedInternalErr(
257+
s.shardContext.GetLogger(),
258+
"unexpected error: mutable state did not have a started workflow task",
259+
nil,
260+
)
256261
}
257262
workflowSnapshot, eventBatches, err := mutableState.CloseTransactionAsSnapshot(
258263
historyi.TransactionPolicyActive,
@@ -261,7 +266,11 @@ func (s *Starter) prepareNewWorkflow(workflowID string) (*creationParams, error)
261266
return nil, err
262267
}
263268
if len(eventBatches) != 1 {
264-
return nil, serviceerror.NewInternal("unable to create 1st event batch")
269+
return nil, softassert.UnexpectedInternalErr(
270+
s.shardContext.GetLogger(),
271+
"unable to create 1st event batch",
272+
nil,
273+
)
265274
}
266275

267276
return &creationParams{

service/history/workflow/mutable_state_impl.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,14 +2129,25 @@ func (ms *MutableStateImpl) IsTransientWorkflowTask() bool {
21292129

21302130
func (ms *MutableStateImpl) ClearTransientWorkflowTask() error {
21312131
if !ms.HasStartedWorkflowTask() {
2132-
return serviceerror.NewInternal("cannot clear transient workflow task when task is missing")
2132+
return softassert.UnexpectedInternalErr(
2133+
ms.logger,
2134+
"cannot clear transient workflow task when task is missing",
2135+
nil,
2136+
)
21332137
}
21342138
if !ms.IsTransientWorkflowTask() {
2135-
return serviceerror.NewInternal("cannot clear transient workflow task when task is not transient")
2139+
return softassert.UnexpectedInternalErr(
2140+
ms.logger,
2141+
"cannot clear transient workflow task when task is not transient",
2142+
nil,
2143+
)
21362144
}
2137-
// this is transient workflow task
21382145
if ms.HasBufferedEvents() {
2139-
return serviceerror.NewInternal("cannot clear transient workflow task when there are buffered events")
2146+
return softassert.UnexpectedInternalErr(
2147+
ms.logger,
2148+
"cannot clear transient workflow task when there are buffered events",
2149+
nil,
2150+
)
21402151
}
21412152
// no buffered event
21422153
emptyWorkflowTaskInfo := &historyi.WorkflowTaskInfo{
@@ -6333,7 +6344,11 @@ func (ms *MutableStateImpl) CloseTransactionAsSnapshot(
63336344

63346345
if len(result.bufferEvents) > 0 {
63356346
// TODO do we need the functionality to generate snapshot with buffered events?
6336-
return nil, nil, serviceerror.NewInternal("cannot generate workflow snapshot with buffered events")
6347+
return nil, nil, softassert.UnexpectedInternalErr(
6348+
ms.logger,
6349+
"cannot generate workflow snapshot with buffered events",
6350+
nil,
6351+
)
63376352
}
63386353

63396354
workflowSnapshot := &persistence.WorkflowSnapshot{
@@ -7017,7 +7032,11 @@ func (ms *MutableStateImpl) closeTransactionPrepareReplicationTasks(
70177032

70187033
if transactionPolicy == historyi.TransactionPolicyPassive &&
70197034
len(ms.InsertTasks[tasks.CategoryReplication]) > 0 {
7020-
return serviceerror.NewInternal("should not generate replication task when close transaction as passive")
7035+
return softassert.UnexpectedInternalErr(
7036+
ms.logger,
7037+
"should not generate replication task when close transaction as passive",
7038+
nil,
7039+
)
70217040
}
70227041

70237042
return nil

0 commit comments

Comments
 (0)