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

[enhancement] Use enums instead of strings for known errors #53

Open
OlegNovosad opened this issue Nov 27, 2024 · 3 comments
Open

[enhancement] Use enums instead of strings for known errors #53

OlegNovosad opened this issue Nov 27, 2024 · 3 comments

Comments

@OlegNovosad
Copy link
Contributor

There are plenty of known errors (e.g. UNSUPPORTED for sensors specific events) and using enum would be less error prone for the package users.

@khamidjon-khamidov
Copy link
Owner

@OlegNovosad I also thought about it but one issue would be we would have to update the library every time new field is added for enum. What do you think?

@OlegNovosad
Copy link
Contributor Author

OlegNovosad commented Nov 27, 2024

We can trysealed classes, e.g.:

sealed class Error {
  final String rawValue;
  
  Error(this.rawValue);
}

class Unsupported extends Error {
  Unsupported() : super("UNSUPPORTED");
}

class Unknown extends Error {
  Unknown(super.rawValue);
}

or NotImplemented, RawError etc.

@OlegNovosad OlegNovosad changed the title Use enums instead of strings for known errors [enhancement] Use enums instead of strings for known errors Nov 28, 2024
@khamidjon-khamidov
Copy link
Owner

khamidjon-khamidov commented Nov 28, 2024

Let's say new error is added by Telegram.

Until we introduce the new enum/sealed type, users would check

if (error is Unknown) { 
    error.rawValue
}

Then after we do the update, they would have to change it again accordingly. I would assume this could be done via extensions by users if needed

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

2 participants