Skip to content

Commit

Permalink
modify err type transfer and fix producer demo panic
Browse files Browse the repository at this point in the history
  • Loading branch information
wangfan committed Jun 26, 2019
1 parent 0a1f313 commit e2a5f8b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion example/talos_producer/TalosProducerDemo.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func main() {
flag.StringVar(&propertyFilename, "conf", "talosProducer.conf", "conf: talosConsumer.conf'")
flag.Parse()

talosProducer, err := producer.NewTalosProducerByFilename(propertyFilename,
var err error
talosProducer, err = producer.NewTalosProducerByFilename(propertyFilename,
client.NewSimpleTopicAbnormalCallback(), new(MyMessageCallback))
if err != nil {
log.Errorf("Init talosProducer failed: %s", err.Error())
Expand Down
19 changes: 12 additions & 7 deletions utils/Utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,24 @@ func HashCode(value []rune) int {
}

func IsTopicNotExist(err error) bool {
return err.(*common.GalaxyTalosException).GetErrorCode() == common.ErrorCode_TOPIC_NOT_EXIST
if talosError, ok := err.(*common.GalaxyTalosException); ok {
return talosError.GetErrorCode() == common.ErrorCode_TOPIC_NOT_EXIST
}
return false
}

func IsPartitionNotServing(err error) bool {
return err.(*common.GalaxyTalosException).GetErrorCode() == common.ErrorCode_PARTITION_NOT_SERVING
if talosError, ok := err.(*common.GalaxyTalosException); ok {
return talosError.GetErrorCode() == common.ErrorCode_PARTITION_NOT_SERVING
}
return false
}

func IsOffsetOutOfRange(err error) bool {
return err.(*common.GalaxyTalosException).GetErrorCode() == common.ErrorCode_MESSAGE_OFFSET_OUT_OF_RANGE
}

func IsUnexpectedError(err error) bool {
return err.(*common.GalaxyTalosException).GetErrorCode() == common.ErrorCode_UNEXPECTED_ERROR
if talosError, ok := err.(*common.GalaxyTalosException); ok {
return talosError.GetErrorCode() == common.ErrorCode_MESSAGE_OFFSET_OUT_OF_RANGE
}
return false
}

func UpdateMessage(msg *message.Message, messageType message.MessageType) {
Expand Down

0 comments on commit e2a5f8b

Please sign in to comment.