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

enum fallback design allows for silent API breakages #268

Open
oguzkocer opened this issue Aug 19, 2024 · 0 comments
Open

enum fallback design allows for silent API breakages #268

oguzkocer opened this issue Aug 19, 2024 · 0 comments
Assignees
Milestone

Comments

@oguzkocer
Copy link
Contributor

Consider the WpErrorCode implementation below:

fn showcase(error_code: WpErrorCode) {
    if let WpErrorCode::CustomError(error_code_as_string) = error_code {
        if error_code_as_string == "foo" {
            // handle the "foo" error
        }
    }

If we were to add a new WpErrorCode::Foo variant, it'll start to fail and has to be handled as such:

fn showcase(error_code: WpErrorCode) {
    if let WpErrorCode::Foo = error_code {
        // handle the "foo" error
    }
}

This kind of silent API breakages are very dangerous. Our design should allow us to add more error variants without breaking the existing implementation.


The same issue can be seen in other enum fallbacks as well. For example, if we were to add a new variant to PostTypeCapabilities, it can break the same way.

@oguzkocer oguzkocer added this to the 0.3 milestone Aug 19, 2024
@oguzkocer oguzkocer self-assigned this Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant