cacti icon indicating copy to clipboard operation
cacti copied to clipboard

bug(verifier): startMonitor resolves successfully after watchBlocks startup failure

Open malsomesh9 opened this issue 7 months ago • 1 comments

Describe the bug

Verifier.startMonitor() catches errors thrown while creating/subscribing to the watch blocks observable, logs them, deletes the monitor entry, but does not rethrow or reject:

} catch (err) {
  this.log.error(`##Error: startMonitor, ${err}`);
  this.runningMonitors.delete(appId);
}

Because the method returns Promise<void>, callers can receive a resolved promise even though monitoring failed to start.

To Reproduce

  1. Use a ledger API client whose watchBlocksV1() or watchBlocksAsyncV1() throws, rejects, or returns no observable.
  2. Call await verifier.startMonitor(appId, options, listener).
  3. Observe that the call resolves after logging the error instead of rejecting.

Expected behavior

startMonitor() should reject when the monitor cannot be started, so callers can handle the failure and avoid assuming monitoring is active.

Actual behavior

startMonitor() swallows the startup error and resolves successfully after logging.

Impact

Applications can believe block/event monitoring is active when it failed to start. This can make monitoring failures silent unless logs are inspected.

Suggested fix

Rethrow the caught error after cleanup, or return a status/result that explicitly tells callers the monitor was not started.

malsomesh9 avatar Apr 16 '26 09:04 malsomesh9

Hey @RafaelAPB @malsomesh9 I would like to work on this issue My understanding of the issue In Verifier.startMonitor(), the catch block logs the error and cleans up runningMonitors but never rethrows. Since it's an async function, the swallowed exception causes the promise to resolve instead of reject — callers have no way to know monitoring failed.

My fix Add a rethrow in the catch block so the error propagates to the caller. Also update the existing test in verifier.test.ts which was written expecting the broken behavior (asserting the promise resolves on error) — it should instead assert that the promise rejects.

Can I be assigned to this, or should I open a PR directly?

AgrimTawani avatar Apr 16 '26 21:04 AgrimTawani