-
Notifications
You must be signed in to change notification settings - Fork 904
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
Refactor errors to be more specific #3067
Conversation
Similarly for EventLoop::with_user_event and EventLoopBuilder::with_user_event
ecfd116
to
c79d885
Compare
c79d885
to
2ce9572
Compare
ba28abf
to
ad397f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also a good idea to extract the "could not find any backends" error in linux/mod.rs
into its own variant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely love this change, it's a great improvement imo!
Only reviewed the cross-platform stuff and Web, I think Web errors in general need an overhaul so I'm gonna leave things as they are.
Fully agreed, ideally I'd get rid of the generic |
@@ -1,142 +1,36 @@ | |||
use std::panic::Location; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of keeping this module then in the end? The OsError
sounds like it should be in the platform module, since it depends on the platform. We could maybe name it differently, like PlatformError
.
} | ||
} | ||
|
||
impl std::error::Error for RequestIgnored {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think nothing stops from doing a proper import at the top.
/// The request to change the inner size synchronously was ignored. | ||
/// | ||
/// See [`InnerSizeWriter::request_inner_size`] for details. | ||
#[derive(Debug)] // Explicitly not other traits, in case we want to extend it in the future | ||
pub struct RequestIgnored { | ||
_priv: (), | ||
} | ||
|
||
impl fmt::Display for RequestIgnored { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { | ||
f.write_str("the request was ignored") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason this error is here and not on the window
for example?
/// Application has exit with an error status. | ||
ExitFailure(i32), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is likely gone with the recent rework.
/// The error type for when the requested operation is not supported by the backend. | ||
#[derive(Debug)] | ||
pub struct ActivationTokenNotFound { | ||
_marker: (), | ||
} | ||
|
||
impl fmt::Display for ActivationTokenNotFound { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it was changed to something that has nothing to do with the activation token. It can't be not found. It's either supported or not supported, which is why it was NotSupportedError
.
#[derive(Debug)] | ||
pub enum WindowError { | ||
/// The operation is not supported by the backend. | ||
NotSupported(NotSupportedError), | ||
/// The OS cannot perform the operation. | ||
Os(OsError), | ||
} | ||
|
||
impl fmt::Display for WindowError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { | ||
match self { | ||
Self::NotSupported(e) => write!(f, "window operation failed: {e}"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could just name it a RequestError
. I'm also not a fan of TODO
items in top level stuff, could just open an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack'ing the Android changes, good stuff!
event::{self, InnerSizeWriter, StartCause}, | ||
event_loop::{self, ControlFlow, EventLoopWindowTarget as RootELW}, | ||
event_loop::{ | ||
self, ControlFlow, EventLoopCreationError, EventLoopRunError, | ||
EventLoopWindowTarget as RootELW, | ||
}, | ||
platform::pump_events::PumpStatus, | ||
window::{ | ||
self, CursorGrabMode, ImePurpose, ResizeDirection, Theme, WindowButtons, WindowLevel, | ||
self, CursorGrabMode, ImePurpose, NotSupportedError, ResizeDirection, Theme, WindowButtons, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it just me who thinks these self
imports are funky?
ping @madsmtm what should we do with this now? |
I still believe this is a change that should be done, but it'll need work, so I'll close this PR, and try to open new, smaller scoped ones for these error changes. |
Move errors out of the generic
error
module, and into the module where they're used.This should help the user with actually handling the errors (instead of just propagating them), and with seeing what kind of errors a method can return (more work is still needed in this area, but this is a first step towards that).
The public changes are:
error::ExternalError::Ignored
->event::RequestIgnored
.error::EventLoopError
is split into:event_loop::EventLoopCreationError
(with less variants).event_loop::EventLoopRunError
(with less variants).platform::startup_notify::EventLoopExtStartupNotify::request_activation_token
now errors withplatform::startup_notify::ActivationTokenNotFound
instead oferror::NotSupportedError
.error::ExternalError
->window::WindowError
.error::NotSupportedError
->window::NotSupportedError
.A few documents that guide decision making here:
std::error
Checklist:
CHANGELOG.md
if knowledge of this change could be valuable to usersBuilds upon #3066, DO NOT MERGE YET!