Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Truncate execution error message only when size exceeds limit (#533)
Browse files Browse the repository at this point in the history
* Bump propeller

Signed-off-by: Kevin Su <[email protected]>

* Fixed slice bounds out of range

Signed-off-by: Kevin Su <[email protected]>

* Fixed slice bounds out of range

Signed-off-by: Kevin Su <[email protected]>

* update go.mod

Signed-off-by: Kevin Su <[email protected]>

* update go.mod

Signed-off-by: Kevin Su <[email protected]>

* update

Signed-off-by: Kevin Su <[email protected]>

* Add tests

Signed-off-by: Kevin Su <[email protected]>

* lint

Signed-off-by: Kevin Su <[email protected]>

---------

Signed-off-by: Kevin Su <[email protected]>
  • Loading branch information
pingsutw authored Mar 6, 2023
1 parent 9508833 commit 326ca45
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pkg/repositories/transformers/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ func FromExecutionModel(executionModel models.Execution, opts *ExecutionTransfor
}
if closure.GetError() != nil && opts != nil && opts.TrimErrorMessage && len(closure.GetError().Message) > 0 {
trimmedErrOutputResult := closure.GetError()
trimmedErrOutputResult.Message = trimmedErrOutputResult.Message[0:trimmedErrMessageLen]
if len(trimmedErrOutputResult.Message) > trimmedErrMessageLen {
trimmedErrOutputResult.Message = trimmedErrOutputResult.Message[0:trimmedErrMessageLen]
}
closure.OutputResult = &admin.ExecutionClosure_Error{
Error: trimmedErrOutputResult,
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/repositories/transformers/node_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ func FromNodeExecutionModel(nodeExecutionModel models.NodeExecution, opts *Execu
}
if closure.GetError() != nil && opts != nil && opts.TrimErrorMessage && len(closure.GetError().Message) > 0 {
trimmedErrOutputResult := closure.GetError()
trimmedErrOutputResult.Message = trimmedErrOutputResult.Message[0:trimmedErrMessageLen]
if len(trimmedErrOutputResult.Message) > trimmedErrMessageLen {
trimmedErrOutputResult.Message = trimmedErrOutputResult.Message[0:trimmedErrMessageLen]
}
closure.OutputResult = &admin.NodeExecutionClosure_Error{
Error: trimmedErrOutputResult,
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/repositories/transformers/task_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,9 @@ func FromTaskExecutionModel(taskExecutionModel models.TaskExecution, opts *Execu
}
if closure.GetError() != nil && opts != nil && opts.TrimErrorMessage && len(closure.GetError().Message) > 0 {
trimmedErrOutputResult := closure.GetError()
trimmedErrOutputResult.Message = trimmedErrOutputResult.Message[0:trimmedErrMessageLen]
if len(trimmedErrOutputResult.Message) > trimmedErrMessageLen {
trimmedErrOutputResult.Message = trimmedErrOutputResult.Message[0:trimmedErrMessageLen]
}
closure.OutputResult = &admin.TaskExecutionClosure_Error{
Error: trimmedErrOutputResult,
}
Expand Down
24 changes: 22 additions & 2 deletions pkg/repositories/transformers/task_execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ func TestFromTaskExecutionModel_Error(t *testing.T) {
Phase: core.WorkflowExecution_FAILED,
OutputResult: &admin.ExecutionClosure_Error{Error: execErr},
})
taskExecution, err := FromTaskExecutionModel(models.TaskExecution{
taskExecutionModel := models.TaskExecution{
TaskExecutionKey: models.TaskExecutionKey{
TaskKey: models.TaskKey{
Project: "project",
Expand All @@ -606,14 +606,34 @@ func TestFromTaskExecutionModel_Error(t *testing.T) {
InputURI: "input uri",
Duration: duration,
Closure: closureBytes,
}, &ExecutionTransformerOptions{
}
taskExecution, err := FromTaskExecutionModel(taskExecutionModel, &ExecutionTransformerOptions{
TrimErrorMessage: true,
})

expectedExecErr := execErr
expectedExecErr.Message = string(make([]byte, trimmedErrMessageLen))
assert.Nil(t, err)
assert.True(t, proto.Equal(expectedExecErr, taskExecution.Closure.GetError()))

extraShortErrMsg := string(make([]byte, 10))
execErr = &core.ExecutionError{
Code: "CODE",
Message: extraShortErrMsg,
Kind: core.ExecutionError_USER,
}
closureBytes, _ = proto.Marshal(&admin.ExecutionClosure{
Phase: core.WorkflowExecution_FAILED,
OutputResult: &admin.ExecutionClosure_Error{Error: execErr},
})
taskExecutionModel.Closure = closureBytes
taskExecution, err = FromTaskExecutionModel(taskExecutionModel, &ExecutionTransformerOptions{
TrimErrorMessage: true,
})
expectedExecErr = execErr
expectedExecErr.Message = string(make([]byte, 10))
assert.Nil(t, err)
assert.True(t, proto.Equal(expectedExecErr, taskExecution.Closure.GetError()))
}

func TestFromTaskExecutionModels(t *testing.T) {
Expand Down

0 comments on commit 326ca45

Please sign in to comment.