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

When Jagex/WOM adds a new metric, the package breaks #81

Open
Sharpienero opened this issue Feb 22, 2025 · 0 comments
Open

When Jagex/WOM adds a new metric, the package breaks #81

Sharpienero opened this issue Feb 22, 2025 · 0 comments

Comments

@Sharpienero
Copy link
Contributor

Sharpienero commented Feb 22, 2025

Fixed Unknown Enum Handling for Future API Additions

Problem
The package would break when a new metric was added to the Wise Old Man API. This creates an exception that would throw if trying to access a route that contained the new metric.

Solution
Implement an error handler that returns Metric.Unknown in the case where the current version doesn't contain said metric, but still return the data. This was achieved by creating a new class called MetaEnum, that I passed into the metaclass param for BaseEnum. Not sure if this is really the right way to do this, or if you want me to change it, but the test class I created passes. I tried to do it via the discussed _missing_ keyword, but I couldn't figure out why that method was never being called.

class MetaEnum(EnumMeta):
    def __getitem__(cls: MetaEnum, name: str) -> t.Any:
        try:
            return super().__getitem__(name)
        except KeyError:
            print(
                f"{name!r} is not a valid {cls.__name__} variant. "
                "Please report this issue on github at https://github.com/Jonxslays/wom.py/issues/new"
            )
            return cls.Unknown

This fix can be found here: #82

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant