parent
d699d35107
commit
607954bfc3
|
@ -93,7 +93,7 @@ func (m *NodeManager) startNode(config *params.NodeConfig) (<-chan struct{}, err
|
|||
signal.Send(signal.Envelope{
|
||||
Type: signal.EventNodeCrashed,
|
||||
Event: signal.NodeCrashEvent{
|
||||
Error: fmt.Errorf("%v: %v", ErrNodeStartFailure, startErr).Error(),
|
||||
Error: fmt.Errorf("%v: %v", ErrNodeStartFailure, startErr),
|
||||
},
|
||||
})
|
||||
return
|
||||
|
@ -117,7 +117,7 @@ func (m *NodeManager) startNode(config *params.NodeConfig) (<-chan struct{}, err
|
|||
signal.Send(signal.Envelope{
|
||||
Type: signal.EventNodeCrashed,
|
||||
Event: signal.NodeCrashEvent{
|
||||
Error: ErrRPCClient.Error(),
|
||||
Error: ErrRPCClient,
|
||||
},
|
||||
})
|
||||
return
|
||||
|
|
|
@ -10,13 +10,13 @@ import (
|
|||
// HaltOnPanic recovers from panic, logs issue, sends upward notification, and exits
|
||||
func HaltOnPanic() {
|
||||
if r := recover(); r != nil {
|
||||
strErr := fmt.Sprintf("%v: %v", ErrNodeRunFailure, r)
|
||||
err := fmt.Errorf("%v: %v", ErrNodeRunFailure, r)
|
||||
|
||||
// send signal up to native app
|
||||
signal.Send(signal.Envelope{
|
||||
Type: signal.EventNodeCrashed,
|
||||
Event: signal.NodeCrashEvent{
|
||||
Error: strErr,
|
||||
Error: err,
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
@ -9,8 +9,9 @@ import "C"
|
|||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/status-im/status-go/geth/log"
|
||||
"sync"
|
||||
|
||||
"github.com/status-im/status-go/geth/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -39,7 +40,16 @@ type Envelope struct {
|
|||
|
||||
// NodeCrashEvent is special kind of error, used to report node crashes
|
||||
type NodeCrashEvent struct {
|
||||
Error string `json:"error"`
|
||||
Error error `json:"error"`
|
||||
}
|
||||
|
||||
// MarshalJSON implements the json.Marshaller interface.
|
||||
func (e NodeCrashEvent) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(struct {
|
||||
Error string `json:"error"`
|
||||
}{
|
||||
Error: e.Error.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
// NodeNotificationHandler defines a handler able to process incoming node events.
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package signal
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNodeCrashEventJSONMarshalling(t *testing.T) {
|
||||
errorMsg := "TestNodeCrashEventJSONMarshallingError"
|
||||
expectedJSON := fmt.Sprintf(`{"error":"%s"}`, errorMsg)
|
||||
nodeCrashEvent := &NodeCrashEvent{
|
||||
Error: errors.New(errorMsg),
|
||||
}
|
||||
marshalled, err := json.Marshal(nodeCrashEvent)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedJSON, string(marshalled))
|
||||
}
|
|
@ -20,7 +20,7 @@ func HaltOnPanic() {
|
|||
signal.Send(signal.Envelope{
|
||||
Type: signal.EventNodeCrashed,
|
||||
Event: signal.NodeCrashEvent{
|
||||
Error: err.Error(),
|
||||
Error: err,
|
||||
},
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue