issork / gift

Godot IRC For Twitch addon
MIT License
150 stars 23 forks source link

Fix race condition exception by checking badge key exists #26

Closed jynus closed 1 year ago

jynus commented 1 year ago

Enabling disk_cache can lead to an exception (invalid_index) when changing channel:

Invalid get index 'badge_sets' (on base 'Dictionary'). (gift_node.gd:525)

We short-circuit the get_badge_mapping (and also, as a side effect, we lower the ciclomatic complexity of the method) so that when there is a missing key the right thing happens.

This way we "return early" in the three cases: if it is cached on memory, if it is cached on disk, or if we have to retrieve it from Twitch/HTTPS.

Fixes #25

issork commented 1 year ago

Looks good to me. Thanks!