TheDrone7 / shieldbow

An all-purpose league of legends API Client.
https://shieldbow.thedrone7.dev/
GNU General Public License v3.0
35 stars 6 forks source link

[BUG] Bug with perk style being 0 and causing an error #46

Closed ClaraSmyth closed 1 year ago

ClaraSmyth commented 1 year ago

Describe the bug There is an error with the match api where the players raw data sometimes returns with a perk style of 0 which causes shieldbow to throw an error.

There is an open issue on the riot developer relations about this bug: https://github.com/RiotGames/developer-relations/issues/724

The issue occurs because data.style is 0 and it cannot find any rune tree with an id of 0 which causes an error on line 51 because this.tree is undefined. When this occurs the actual runes selection data is still intact its just the style property.

Line 50/51 of ./src/structures/api/Perks.ts

    this.tree = runeTrees.find((t) => t.id === data.style)!;
    const runes = this.tree.slots.map((r) => [...r.values()]).flat();

Console Error

/home/clara/Repos/test/test2/node_modules/shieldbow/dist/structures/api/Perks.js:45
        const runes = this.tree.slots.map((r) => [...r.values()]).flat();
                                ^

TypeError: Cannot read properties of undefined (reading 'slots')
    at PerkStyle (/home/clara/Repos/test/test2/node_modules/shieldbow/src/structures/api/Perks.ts:73:3)
    at Perks (/home/clara/Repos/test/test2/node_modules/shieldbow/src/structures/api/Perks.ts:87:2)
    at Participant (/home/clara/Repos/test/test2/node_modules/shieldbow/src/structures/api/Participant.ts:464:18)
    at <anonymous> (/home/clara/Repos/test/test2/node_modules/shieldbow/src/structures/api/Team.ts:60:14)
    at Array.map (<anonymous>)
    at Team (/home/clara/Repos/test/test2/node_modules/shieldbow/src/structures/api/Team.ts:59:38)
    at Match (/home/clara/Repos/test/test2/node_modules/shieldbow/src/structures/api/Match.ts:122:27)
    at MatchManager.fetch (/home/clara/Repos/test/test2/node_modules/shieldbow/src/managers/MatchManager.ts:81:21)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///home/clara/Repos/test/test2/[eval1]:30:13

Node.js v19.7.0

To Reproduce

await client.initialize({
  cache: true,
  // storage: false,
  storage: { enable: { dragon: true, api: false } },
  region: "euw",
  logger: { enable: true, level: "TRACE" },
  ratelimiter: {
    strategy: "spread",
    throw: true,
    retry: { retries: 5, retryDelay: 5000 },
  },
  fetch: {
    champions: false,
    items: true,
    runes: true,
    summonerSpells: true,
  },
})

// This is a match id where the bug occurs
const match = await client.matches.fetch('EUW1_6316245747');
console.log(match);

Expected behavior When fetching a match it should return a match but instead throws an error.

Desktop (please complete the following information):

Additional Context Im not sure how you would prefer to handle the error however I have fixed it on my own fork by just using the selected runes to get the rune tree and not use the style property at all.

Using this line

    this.tree = runeTrees.find((r) => r.slots.some((s) => s.some((m) => m.id === data.selections[0].perk)))!;
TheDrone7 commented 1 year ago

Halfway wanna classify this as a wontfix but if https://github.com/RiotGames/developer-relations/issues/724 doesn't get resolved by next weekend, will add a workaround.

TheDrone7 commented 1 year ago

v2.0.2 is being released, and this has been addressed.