[BUG] Incorrect error message when calling the libWrapper API before the libWrapper.Ready hook
ruipin opened this issue · 1 comments
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:
- Write a module which calls
libWrapper.register
before thelibWrapper.Ready
hook fires. - Enter a world and enable the module.
- Refresh.
- 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):
- LibWrapper Version: 1.12.8.0 (and older)
- FoundryVTT Version: Any
- Browser & Version: Any
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.