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

API needs to be able to report failure to detect, errors #21

Open
BartMassey opened this issue Aug 13, 2022 · 7 comments
Open

API needs to be able to report failure to detect, errors #21

BartMassey opened this issue Aug 13, 2022 · 7 comments

Comments

@BartMassey
Copy link

Right now if something goes wrong — can't detect mode, error happens during detection attempt — detect() returns Mode::Light. Would be a lot better to provide some version of this that could return a Result.

@edfloreshz
Copy link
Collaborator

I believe this is by design, when a failure occurs Mode::Light is taken as the fallback mode.

Adding a Result would over-complicate things in my opinion, as an alternative I would suggest adding an Error variant to the Mode enum.

@BartMassey
Copy link
Author

An Error "mode" means that every match against mode will need to handle this case. A Result can be checked for, leaving an actual mode to work with.

If the endpoint uses Result<Mode, Error> one can get the old behavior by

detect().unwrap_or(Mode::Light)

if desired.

@edfloreshz
Copy link
Collaborator

@frewsxcv What do you think? I think I brought this up at some point.

@frewsxcv
Copy link
Owner

Having it return a Result seems reasonable to me

@Rudxain
Copy link

Rudxain commented Sep 16, 2024

Error variant

Isn't Default supposed to be for that?

@BartMassey
Copy link
Author

Error variant

Isn't Default supposed to be for that?

I don't understand. Can you give an example of how Default might be useful here?

@Rudxain
Copy link

Rudxain commented Sep 19, 2024

/// Unspecified
Default,

That variant can be returned when the color-scheme is unknown for any reason.

But if we want to give more info to the API users, then wrapping Mode in a Result or Option is appropriate, as there's a difference between "something went very wrong whilst trying to fetch theme" and "no error happened, but theme is unknown for some reason"

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

4 participants