ruipin/fvtt-lib-wrapper

Improve call stack for Hooks

Closed this issue · 1 comments

Due to Foundry swallowing exceptions that occur inside hooks, libWrapper hooks Hooks._call to catch any unhandled exceptions.

However, this leads to very ugly call stacks any time a hook is triggered, which leads some people to mistakenly believe that an issue is caused by libWrapper, when libWrapper was not involved.

Ideally, we should improve this so that the hooks callstack isn't polluted by libWrapper. Multiple possibilities exist, e.g.:

  1. Do not decorate the Hooks._call wrapper.
  2. Override the Hooks._call wrapper, instead of wrapping it, reducing the number of libWrapper entries in the callstack, and avoid rethrowing.
  3. Move this hook to a different file not called errors.js, e.g. hooks-listener.js.

This is done in v1.5.3.0.

Now, the Hooks._call wrapper is patched from the original without using libWrapper and is no longer decorated, avoiding the callstack pollution.