Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: library.getContents() sometimes returns an empty JSON array #4695

Closed
Azhrei opened this issue Feb 15, 2024 · 0 comments · Fixed by #4696
Closed

[Bug]: library.getContents() sometimes returns an empty JSON array #4695

Azhrei opened this issue Feb 15, 2024 · 0 comments · Fixed by #4696
Labels

Comments

@Azhrei
Copy link
Member

Azhrei commented Feb 15, 2024

Describe the Bug

Calling library.getContents() can often return an empty JSON array when there are multiple properties and macros on the Lib: token.

(See this Discord post.)

To Reproduce

  1. Place this code into a macro inside a campaign with one or more Lib: tokens:
[r, foreach(vTokenLibrary, library.listTokenLibraries(), "<br>"), code: {
    [r: vNameSpace = json.get(vTokenLibrary, "namespace")]
    [library.getContents(vNameSpace)]
}]
  1. When executed, the output will typically be one line per Lib: token with an empty set of brackets as the value. (Sometimes it may work. See below.)

Expected Behaviour

Each Lib: token that contains macros or properties should produce a non-empty list of those values.

Here is example output from a campaign with multiple Lib: tokens showing how the output should look. Note that the first Lib: token, Coords, has no macros and no properties.

  | Anonymous User: Coords []
  GlobalsSRDPF ["property/elevation","property/editonload","property/daylast","property/tokenuncimgchange","property/fgmsecret","property/maps","property/hpbar","property/startmap","property/monthlast","property/skillsindex","property/tempmodlist","property/deathpoints","property/tempmodtogglesets","property/yearlast","property/playersgm","property/system","property/mapstemplate","property/handouts","property/systems","property/skilltype","property/skillssys","property/deathpoint","property/hpbars"]
  CannedSpeech_v1 ["macro/displaySpeech","macro/Canned Speech Frame","macro/Launch Canned Speech","macro/Say Speech","macro/Edit Speech","macro/Manage Speech","macro/Edit Speech .alt","macro/Speech.css","macro/onCampaignLoad","macro/Manage displayPrefs","macro/json.psort","property/elevation","property/jaw_speech_display_prefs","property/jaw_display_prefs","property/prefs"]
  cifTemplates ["macro/TemplateInfo","macro/drawTemplate","macro/onCampaignLoad","macro/removeTemplate","macro/lastTemplateDrawn","macro/SetSourceMap","property/elevation","property/ac","property/constitution","property/strength","property/sourcemap","property/hp","property/description","property/charisma","property/intelligence","property/wisdom","property/dexterity","property/lasttemplatedrawn","property/defense","property/movement"]
  disguise ["macro/Disguise","macro/autoDisguiseButton","macro/Use Disguise","macro/onCampaignLoad","property/elevation","property/h.disguise","property/h.disguisemacro","property/ac","property/constitution","property/strength","property/hp","property/description","property/charisma","property/intelligence","property/wisdom","property/dexterity","property/defense","property/movement"]
  chat ["macro/output","macro/<b>Impersonate</b>","macro/getGMNames","macro/output.basic","macro/json.type","macro/getTokenInfo","macro/icc","macro/updateTargets","macro/onCampaignLoad","macro/jsonToVars","macro/validateTokenInfo","property/elevation","property/bot_doortimer","property/ac","property/rpe.options","property/constitution","property/rpe.macrogroups","property/strength","property/hp","property/description","property/rpe.allindexes","property/charisma","property/intelligence","property/wisdom","property/dexterity","property/defense","property/movement"]
  players ["macro/output","macro/<b>Debug Off</b>","macro/<b>Debug On</b>","macro/watch","macro/chat","macro/text","macro/label","macro/onCampaignLoad","macro/script","macro/pause","property/elevation","property/ac","property/rpe.options","property/constitution","property/rpe.macrogroups","property/strength","property/hp","property/description","property/rpe.allindexes","property/charisma","property/intelligence","property/wisdom","property/dexterity","property/defense","property/movement"]

Screenshots

In many cases, executing the above macro will produce output that looks like this:
| Anonymous User: Coords []
GlobalsSRDPF []
CannedSpeech_v1 []
cifTemplates []
disguise []
chat []
players []



### MapTool Info

_No response_

### Desktop

_No response_

### Additional Context

It appears that `listLibraryContents()` from `src/main/java/net/rptools/maptool/client/functions/LibraryFunctions.java` is creating a `CompletableFuture` but not waiting for it to finish, so the JSON object is returned and (potentially) used before being populated with data.
@Azhrei Azhrei added the bug label Feb 15, 2024
github-merge-queue bot pushed a commit that referenced this issue Feb 15, 2024
Fix for #4695: library.getContents() returns empty JSON sometimes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant