Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yycptt committed Jan 12, 2023
1 parent 414e188 commit fea053e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
22 changes: 11 additions & 11 deletions common/persistence/serialization/serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ type (

// UnknownEncodingTypeError is an error type for unknown or unsupported encoding type
UnknownEncodingTypeError struct {
encodingTypeStr string
supportedEncodingStr []string
encodingTypeStr string
expectedEncodingStr []string
}

serializerImpl struct {
Expand Down Expand Up @@ -261,27 +261,27 @@ func (t *serializerImpl) serialize(p proto.Marshaler, encodingType enumspb.Encod
// NewUnknownEncodingTypeError returns a new instance of encoding type error
func NewUnknownEncodingTypeError(
encodingTypeStr string,
supportedEncoding ...enumspb.EncodingType,
expectedEncoding ...enumspb.EncodingType,
) error {
if len(supportedEncoding) == 0 {
if len(expectedEncoding) == 0 {
for encodingType := range enumspb.EncodingType_name {
supportedEncoding = append(supportedEncoding, enumspb.EncodingType(encodingType))
expectedEncoding = append(expectedEncoding, enumspb.EncodingType(encodingType))
}
}
supportedEncodingStr := make([]string, 0, len(supportedEncoding))
for _, encodingType := range supportedEncoding {
supportedEncodingStr = append(supportedEncodingStr, encodingType.String())
expectedEncodingStr := make([]string, 0, len(expectedEncoding))
for _, encodingType := range expectedEncoding {
expectedEncodingStr = append(expectedEncodingStr, encodingType.String())
}
return &UnknownEncodingTypeError{
encodingTypeStr: encodingTypeStr,
supportedEncodingStr: supportedEncodingStr,
encodingTypeStr: encodingTypeStr,
expectedEncodingStr: expectedEncodingStr,
}
}

func (e *UnknownEncodingTypeError) Error() string {
return fmt.Sprintf("unknown or unsupported encoding type %v, supported types: %v",
e.encodingTypeStr,
strings.Join(e.supportedEncodingStr, ","),
strings.Join(e.expectedEncodingStr, ","),
)
}

Expand Down
32 changes: 15 additions & 17 deletions service/history/queues/executable.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,21 @@ func (e *executableImpl) Execute() (retErr error) {
headers.NewBackgroundCallerInfo(namespaceName.String()),
)

defer e.capturePanic(&retErr)
defer func() {
if panicObj := recover(); panicObj != nil {
err, ok := panicObj.(error)
if !ok {
err = serviceerror.NewInternal(fmt.Sprintf("panic: %v", panicObj))
}

e.logger.Error("Panic is captured", tag.SysStackTrace(string(debug.Stack())), tag.Error(err))
retErr = err

// we need to guess the metrics tags here as we don't know which execution logic
// is actually used which is upto the executor implementation
e.taggedMetricsHandler = e.metricsHandler.WithTags(e.estimateTaskMetricTag()...)
}
}()

startTime := e.timeSource.Now()

Expand Down Expand Up @@ -519,19 +533,3 @@ func (e *executableImpl) estimateTaskMetricTag() []metrics.Tag {
metrics.OperationTag(taskType), // for backward compatibility
}
}

func (e *executableImpl) capturePanic(retError *error) {
if panicObj := recover(); panicObj != nil {
err, ok := panicObj.(error)
if !ok {
err = serviceerror.NewInternal(fmt.Sprintf("panic: %v", panicObj))
}

e.logger.Error("Panic is captured", tag.SysStackTrace(string(debug.Stack())), tag.Error(err))
*retError = err

// we need to guess the metrics tags here as we don't know which execution logic
// is actually used which is upto the executor implementation
e.taggedMetricsHandler = e.metricsHandler.WithTags(e.estimateTaskMetricTag()...)
}
}

0 comments on commit fea053e

Please # to comment.