ruipin / fvtt-lib-wrapper

Library for Foundry VTT which provides module developers with a simple way to modify core Foundry VTT code, while reducing the likelihood of conflict with other modules.
GNU Lesser General Public License v3.0
35 stars 15 forks source link

[BUG] Incorrect error message when calling the libWrapper API before the libWrapper.Ready hook #72

Closed ruipin closed 2 years ago

ruipin commented 2 years ago

Describe the bug When trying to register a wrapper before the libWrapper.Ready hook, if this happens before game.modules is available, libWrapper will try to construct an error message and fail with an error message like:

[Detected 2 packages: lib-wrapper, XYZ]
    at PackageInfo.get exists [as exists] (libWrapper-package_info.js:328)
    at de (libWrapper-api.js:273)
    at Function.šŸŽregister [as register] (libWrapper-api.js:471)
    at XYZ.js:5

To Reproduce Steps to reproduce the behavior:

  1. Write a module which calls libWrapper.register before the libWrapper.Ready hook fires.
  2. Enter a world and enable the module.
  3. Refresh.
  4. See the error in the JS console.

Expected behavior libWrapper should give the error Not allowed to register wrappers before the 'libWrapper.Ready' hook fires instead.

Technical Details (please complete the following information):

Additional context This seems to be caused by api.js:475, which throws a LibWrapperPackageError exception when libWrapper isn't ready yet, which will trigger a PackageInfo::exists call during the error message construction.

This PackageInfo::exists method does not correctly handle the case where game.modules is undefined.

ruipin commented 2 years ago

Fixed by v1.12.9.0. Closing.