Open trekze opened 3 years ago
Any chance to get some feedback on the above? Not being able to recover gracefully from an error thrown by the SDK is kind of a deal-breaker, so curious to hear if I'm doing something wrong.
@hmexx can you try catching error inside .on("confirmation", ...
block? looks like sdk emits confirmation (=false
) even for the failure case: https://github.com/harmony-one/sdk/blob/master/packages/harmony-transaction/src/transactionBase.ts#L191
@gupadhyaya Hey!
Thanks for getting back to me. What would the above minimal code look like with your suggestion? I'm not super familiar with emitters but as you can see there is already an .on("error, ...
in there.
Hi, @hmexx , can you try this
try {
let sendoptions = {
from: from,
gasLimit: '250000',
gasPrice: new hmy.utils.Unit(GAS_PRICE_GWEI).asGwei().toWei(),
};
const txn= contract.methods
.transfer(to, new Unit(amount).asOne().toWei())
.send(sendoptions);
txn.on("transactionHash", (_hash) => {
})
.on("receipt", (_receipt) => {
})
.on("confirmation", (confirmation) => {
// try throw here?
})
.on("error", (error) => {
// try throw here?
});
await txn;
} catch (err) {
}
Hi There!
Thank you for suggesting this fix. I will try it out shortly and report back.
I'm putting your suggestion into production now, although having had a second look at it, I think it might semantically identical to what I had before. Will let you know what happens. Unfortunately these uncaught SDK exceptions are very rare (once every couple weeks) so it might be a while.
I'm putting your suggestion into production now, although having had a second look at it, I think it might semantically identical to what I had before. Will let you know what happens. Unfortunately these uncaught SDK exceptions are very rare (once every couple weeks) so it might be a while.
They are not identical, since the eventEmitter happens before the Promise, the try catch only knows when the emitter ends. so the await
only cares about the Promise, not the emitter itself.
Afraid it didn't work. Exception from the SDK took down the process again:
11:20:07: Withdraw: send failure within Harmony, reverting balance for wallet 11949
11:20:07: REJECTED
/path/node_modules/@harmony-js/network/dist/messenger/messenger.js:82
throw new Error(e_1);
^
Error: FetchError: invalid json response body at https://api.s0.t.hmny.io/ reason: Unexpected end of JSON input
at Messenger.<anonymous> (/node_modules/@harmony-js/network/dist/messenger/messenger.js:82:35)
at step (/node_modules/tslib/tslib.js:143:27)
at Object.throw (/node_modules/tslib/tslib.js:124:57)
at rejected (/node_modules/tslib/tslib.js:115:69)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Any ideas?
Afraid it didn't work. Exception from the SDK took down the process again:
11:20:07: Withdraw: send failure within Harmony, reverting balance for wallet 11949 11:20:07: REJECTED /path/node_modules/@harmony-js/network/dist/messenger/messenger.js:82 throw new Error(e_1); ^ Error: FetchError: invalid json response body at https://api.s0.t.hmny.io/ reason: Unexpected end of JSON input at Messenger.<anonymous> (/node_modules/@harmony-js/network/dist/messenger/messenger.js:82:35) at step (/node_modules/tslib/tslib.js:143:27) at Object.throw (/node_modules/tslib/tslib.js:124:57) at rejected (/node_modules/tslib/tslib.js:115:69) at runMicrotasks (<anonymous>) at processTicksAndRejections (node:internal/process/task_queues:96:5)
Any ideas?
@neeboo @potvik
Afraid it didn't work. Exception from the SDK took down the process again:
11:20:07: Withdraw: send failure within Harmony, reverting balance for wallet 11949 11:20:07: REJECTED /path/node_modules/@harmony-js/network/dist/messenger/messenger.js:82 throw new Error(e_1); ^ Error: FetchError: invalid json response body at https://api.s0.t.hmny.io/ reason: Unexpected end of JSON input at Messenger.<anonymous> (/node_modules/@harmony-js/network/dist/messenger/messenger.js:82:35) at step (/node_modules/tslib/tslib.js:143:27) at Object.throw (/node_modules/tslib/tslib.js:124:57) at rejected (/node_modules/tslib/tslib.js:115:69) at runMicrotasks (<anonymous>) at processTicksAndRejections (node:internal/process/task_queues:96:5)
Any ideas?
looks like it happened outside the txnBase.
Any ideas?
I guess can bite the bullet and put the SDK in its own process, with a queueing system, but you should probably get to the bottom of this.
Didn't happen for 10 days, but happened twice in the last 48 hours. I guess it depends on the health of the blockchain.
FYI this still happens, although it doesn't kill our process anymore, since we use pm2
to manage the services.
For some reason I can't seem to gracefully recover from errors thrown in the SDK, despite using the
.on("error"
handler AND wrapping the send function a try catch block. Any ideas why that's the case? Sample code below:And the error that's taking down the process below: