aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemco Bloemen <remco@wicked.ventures>2018-12-21 07:31:13 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2019-01-11 18:26:38 +0800
commit7af0818dffe67483491f99062071b582fba456cb (patch)
tree514f8b32b3e7d2d30cab326652bcc3e3f95e62e0
parent296b3d6311186c7444d9d6763f8ee2d3c373dc14 (diff)
downloaddexon-sol-tools-7af0818dffe67483491f99062071b582fba456cb.tar
dexon-sol-tools-7af0818dffe67483491f99062071b582fba456cb.tar.gz
dexon-sol-tools-7af0818dffe67483491f99062071b582fba456cb.tar.bz2
dexon-sol-tools-7af0818dffe67483491f99062071b582fba456cb.tar.lz
dexon-sol-tools-7af0818dffe67483491f99062071b582fba456cb.tar.xz
dexon-sol-tools-7af0818dffe67483491f99062071b582fba456cb.tar.zst
dexon-sol-tools-7af0818dffe67483491f99062071b582fba456cb.zip
Capture errors in next callbacks
-rw-r--r--packages/sol-tracing-utils/src/trace_collection_subprovider.ts24
1 files changed, 21 insertions, 3 deletions
diff --git a/packages/sol-tracing-utils/src/trace_collection_subprovider.ts b/packages/sol-tracing-utils/src/trace_collection_subprovider.ts
index 25e38768d..8b4ea82f5 100644
--- a/packages/sol-tracing-utils/src/trace_collection_subprovider.ts
+++ b/packages/sol-tracing-utils/src/trace_collection_subprovider.ts
@@ -20,6 +20,24 @@ export interface TraceCollectionSubproviderConfig {
shouldCollectGasEstimateTraces: boolean;
}
+type AsyncFunc = (...args: any[]) => Promise<void>;
+
+// This wrapper outputs errors to console even if the promise gets ignored
+// we need this because web3-provider-engine does not handler promises in
+// the after function of next(after).
+function logErrors(fn: AsyncFunc): AsyncFunc {
+ async function wrapped(...args: any[]): Promise<void> {
+ try {
+ await fn(...args);
+ } catch (e) {
+ // tslint:disable-next-line no-console
+ console.error(e);
+ throw e;
+ }
+ }
+ return wrapped;
+}
+
// Because there is no notion of a call trace in the Ethereum rpc - we collect them in a rather non-obvious/hacky way.
// On each call - we create a snapshot, execute the call as a transaction, get the trace, revert the snapshot.
// That allows us to avoid influencing test behaviour.
@@ -74,7 +92,7 @@ export abstract class TraceCollectionSubprovider extends Subprovider {
next();
} else {
const txData = payload.params[0];
- next(this._onTransactionSentAsync.bind(this, txData));
+ next(logErrors(this._onTransactionSentAsync.bind(this, txData)));
}
return;
@@ -83,7 +101,7 @@ export abstract class TraceCollectionSubprovider extends Subprovider {
next();
} else {
const callData = payload.params[0];
- next(this._onCallOrGasEstimateExecutedAsync.bind(this, callData));
+ next(logErrors(this._onCallOrGasEstimateExecutedAsync.bind(this, callData)));
}
return;
@@ -92,7 +110,7 @@ export abstract class TraceCollectionSubprovider extends Subprovider {
next();
} else {
const estimateGasData = payload.params[0];
- next(this._onCallOrGasEstimateExecutedAsync.bind(this, estimateGasData));
+ next(logErrors(this._onCallOrGasEstimateExecutedAsync.bind(this, estimateGasData)));
}
return;