aepp-sdk-js icon indicating copy to clipboard operation
aepp-sdk-js copied to clipboard

State Channels: Unhandled 'error' event

Open Kalovelo opened this issue 3 years ago • 2 comments

It is stated here that you can handle 'error' event. however, there's not a documented way on how to handle that specific case.

Example errors I'd like to handle

here I'd like to retry the connection:

Error handling incoming message:
[Object: null prototype] {
  channel_id: null,
  error: [Object: null prototype] {
    code: 3,
    data: [ [Object: null prototype] ],
    message: 'Rejected',
    request: [Object: null prototype] {}
  },
  id: null,
  jsonrpc: '2.0',
  version: 1
}
UnknownChannelStateError: State Channels FSM entered unknown state
    at enterState (/home//aeternity/state-channel-demo/server/node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:17950:11)
    at handleMessage (/home/apostolos/aeternity/state-channel-demo/server/node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:18026:3)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async dequeueMessage (/home/apostolos/aeternity/state-channel-demo/server/node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:18044:7)

This is quite random:

/home/apostolos/aeternity/state-channel-demo/server/node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:18271
  state === null || state === void 0 ? void 0 : (_state$reject = state.reject) === null || _state$reject === void 0 ? void 0 : _state$reject.call(state, Object.assign(new UnexpectedChannelMessageError(`Unexpected message received:\n\n${JSON.stringify(message)}`), {
                                                                                                                                                                       ^

UnexpectedChannelMessageError: Unexpected message received:

{"jsonrpc":"2.0","method":"channels.info","params":{"channel_id":"ch_2qisVb9Rj2MWbzmCFFZDukGieUMg4nVmxQEbVrwYmJde6J56s1","data":{"event":"died"}},"version":1}
    at handleUnexpectedMessage (/home/apostolos/aeternity/state-channel-demo/server/node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:18271:168)
    at awaitingCallContractCompletion (/home/apostolos/aeternity/state-channel-demo/server/node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:19316:10)
    at handleMessage (/home/apostolos/aeternity/state-channel-demo/server/node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:18026:45)
    at dequeueMessage (/home/apostolos/aeternity/state-channel-demo/server/node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:18044:13)
    at onMessage (/home/apostolos/aeternity/state-channel-demo/server/node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:18123:8)
    at W3CWebSocket.onmessage (/home/apostolos/aeternity/state-channel-demo/server/node_modules/@aeternity/aepp-sdk/dist/aepp-sdk.js:18211:16)
    at W3CWebSocket._dispatchEvent [as dispatchEvent] (/home/apostolos/aeternity/state-channel-demo/server/node_modules/yaeti/lib/EventTarget.js:107:17)
    at W3CWebSocket.onMessage (/home/apostolos/aeternity/state-channel-demo/server/node_modules/websocket/lib/W3CWebSocket.js:234:14)
    at WebSocketConnection.<anonymous> (/home/apostolos/aeternity/state-channel-demo/server/node_modules/websocket/lib/W3CWebSocket.js:205:19)
    at WebSocketConnection.emit (node:events:527:28) {
  wsMessage: [Object: null prototype] {
    jsonrpc: '2.0',
    method: 'channels.info',
    params: [Object: null prototype] {
      channel_id: 'ch_2qisVb9Rj2MWbzmCFFZDukGieUMg4nVmxQEbVrwYmJde6J56s1',
      data: [Object: null prototype] { event: 'died' }
    },
    version: 1
  }
}

Kalovelo avatar Aug 30 '22 08:08 Kalovelo

The first part I think is fixed in #1670. I missed the emitter interface when introduced printing of that error.

Unexpected message received

Is there is a case when this error doesn't get throwed by a method it rised? I would keep 'error' events only for exceptions that can't be throwed because initiated by other peer, like the above error on handling the incomming message.

davidyuk avatar Aug 31 '22 10:08 davidyuk

The rejected was triggered by the node and not by the other participant - I guess that when a node is busy handling other channel connections it may reject new ones which in that case I'd like to catch it and retry the connection.

Kalovelo avatar Aug 31 '22 10:08 Kalovelo