From 0a368e1bf0f1b50f2595fdaf85a336b0a088e3f0 Mon Sep 17 00:00:00 2001 From: Silas Davis <silas@erisindustries.com> Date: Wed, 17 Aug 2016 17:03:13 +0100 Subject: [PATCH] Some narrative comments and avoidance of a panic if we have unexpected events --- event/events.go | 20 +++++++++++--------- rpc/tendermint/test/common.go | 5 +++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/event/events.go b/event/events.go index fa56644e..fab36968 100644 --- a/event/events.go +++ b/event/events.go @@ -24,16 +24,18 @@ import ( "fmt" "github.com/eris-ltd/eris-db/txs" + log "github.com/eris-ltd/eris-logger" go_events "github.com/tendermint/go-events" tm_types "github.com/tendermint/tendermint/types" ) -// TODO improve -// TODO: [ben] yes please ^^^ -// [ben] To improve this we will switch out go-events with eris-db/event so -// that there is no need anymore for this poor wrapper. +// TODO: [Silas] this is a compatibility layer between our event types and +// TODO: go-events. Our ultimate plan is to replace go-events with our own pub-sub +// TODO: code that will better allow us to manage and multiplex events from different +// TODO: subsystems // Oh for a sum type +// We are using this as a marker interface for the type anyEventData interface{} type EventEmitter interface { @@ -63,8 +65,9 @@ func (this *events) Subscribe(subId, event string, cb := func(evt go_events.EventData) { eventData, err := mapToOurEventData(evt) if err != nil { - panic(fmt.Sprintf("Failed to map go-events EventData to our EventData %v", - err)) + log.WithError(err). + WithFields(log.Fields{"event": event}). + Error("Failed to map go-events EventData to our EventData") } callback(eventData) } @@ -138,9 +141,8 @@ func GenerateSubId() (string, error) { } func mapToOurEventData(eventData anyEventData) (txs.EventData, error) { - // While we depend on go-events in the way we do, we don't have much choice - // than to use a generic interface like anyEventData with a type switch. - + // TODO: [Silas] avoid this with a better event pub-sub system of our own + // TODO: that maybe involves a registry of events switch eventData := eventData.(type) { case txs.EventData: return eventData, nil diff --git a/rpc/tendermint/test/common.go b/rpc/tendermint/test/common.go index 98ab3b16..b0d2f07e 100644 --- a/rpc/tendermint/test/common.go +++ b/rpc/tendermint/test/common.go @@ -29,6 +29,11 @@ func TestWrapper(runner func() int) int { return runner() } +// This main function exists as a little convenience mechanism for running the +// delve debugger which doesn't work well from go test yet. In due course it can +// be removed, but it's flux between pull requests should be considered +// inconsequential, so feel free to insert your own code if you want to use it +// as an application entry point for delve debugging. func DebugMain() { t := &testing.T{} TestWrapper(func() int { -- GitLab