ruipin/fvtt-lib-wrapper

[BUG] libWrapper.ignore_conflicts not ignoring "did not chain wrapper" / "replacing OVERRIDE" conflicts

caewok opened this issue · 4 comments

Confirm you have read the above
Appears to be a problem with how libWrapper is handling the lib wrapper.ignore_conflicts method. I am using that method to ignore a potential conflict, but I am still getting a warning message regarding that very conflict.

Describe the bug
The libRuler module overrides Ruler.prototype.moveToken with this call to libWrapper:
libWrapper.register("libruler", "Ruler.prototype.moveToken", libRulerMoveToken, "OVERRIDE");

This is an override because libRuler basically breaks up the moveToken function into parts that are easier for modules to wrap or override.

I am working on code for the Drag Ruler module that wraps this function:
libWrapper.register("drag-ruler", "Ruler.prototype.moveToken", dragRulerMoveToken, "MIXED");

It is a MIXED wrap because Drag Ruler intercepts certain key commands, like spacebar, and does not call moveToken in that circumstance. Otherwise, it will call the wrap function for moveToken.

I am getting an occasional warning from libWrapper about the potential conflict because "drag-ruler did not chain the wrapper." So I put this ignore code in Drag Ruler:
libWrapper.ignore_conflicts("drag-ruler", "libruler", "Ruler.prototype.moveToken");

After doing so, the console reports the following:

libWrapper: Wrapped 'Ruler.prototype.moveToken'. libWrapper-wrapper.js:347:2
libWrapper: Registered a wrapper for 'Ruler.prototype.moveToken' by module 'libruler' with type OVERRIDE. libWrapper-api.js:516:3
libWrapper: Registered a wrapper for 'Ruler.prototype.moveToken' by module 'drag-ruler' with type MIXED. libWrapper-api.js:516:3
libWrapper: Ignoring conflicts involving module 'drag-ruler' and [module 'libruler'] for targets [Ruler.prototype.moveToken]. libWrapper-api.js:631:3

But the console still reports the following warning (which also shows up as a notification in the UI):

libWrapper: Potential conflict detected between module 'drag-ruler' and module 'libruler'.
Module 'drag-ruler' did not chain the wrapper for 'Ruler.prototype.moveToken'. libWrapper-notifications.js:67:10

To Reproduce
I can reproduce this in my system by logging in and then dragging the token and trying to create a waypoint. It would be difficult to reproduce from libWrapper alone, because it is dependent on work-in-progress Drag Ruler code. But if it helps, I could show you where that code is in my git repository. Or happy to help test solutions.

Expected behavior
I would expect that the conflict warning no longer appear once libWrapper.ignore_conflicts is called.

Technical Details (please complete the following information):

  • LibWrapper Version 1.9.0
  • FoundryVTT Version 0.8.8
  • Browser & Version Firefox 91.0.1

Thanks for the bug report.

I've taken a quick look and I think you are correct. It seems the "did not chain the wrapper" conflict is not going through the standard "conflict detected" code path where ignores are applied, but instead triggering the warning/notification directly.

I'll see if I can confirm, and release a hotfix.

Seems this occurred with two types of conflicts:

  1. X did not chain the wrapper for Y
  2. X has higher priority, and is replacing the 'OVERRIDE' registered by Y for Z

The pre-release v1.9.2.0 contains a hotfix. Could you by any chance test it for me and confirm it now ignores things correctly?

I need to do a bit more validation on it. Also want to think about how I can write a unit test for this. But I'll probably release it tomorrow.

Yes, it looked like that worked. Thanks!

Thanks for confirming, I have released v1.9.2.0.

In case you tried the pre-release version, I touched up some things (nothing functional IIRC) but I'd suggest reinstalling it just in case.