Skip to content

Commit

Permalink
gpui: Don't panic on failing to set X11 cursor style (zed-industries#…
Browse files Browse the repository at this point in the history
…21689)

One more panic (well, two) that should be a `log_err`.

Release Notes:

- N/A
  • Loading branch information
cole-miller authored Dec 8, 2024
1 parent 4b93a5c commit ac07b91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions crates/gpui/src/platform/linux/x11/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::time::{Duration, Instant};
use calloop::generic::{FdWrapper, Generic};
use calloop::{EventLoop, LoopHandle, RegistrationToken};

use anyhow::Context as _;
use collections::HashMap;
use http_client::Url;
use smallvec::SmallVec;
Expand Down Expand Up @@ -1417,9 +1418,10 @@ impl LinuxClient for X11Client {
..Default::default()
},
)
.expect("failed to change window cursor")
.check()
.unwrap();
.anyhow()
.and_then(|cookie| cookie.check().anyhow())
.context("setting cursor style")
.log_err();
}

fn open_uri(&self, uri: &str) {
Expand Down
10 changes: 10 additions & 0 deletions crates/util/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ pub trait ResultExt<E> {
/// Assert that this result should never be an error in development or tests.
fn debug_assert_ok(self, reason: &str) -> Self;
fn warn_on_err(self) -> Option<Self::Ok>;
fn anyhow(self) -> anyhow::Result<Self::Ok>
where
E: Into<anyhow::Error>;
}

impl<T, E> ResultExt<E> for Result<T, E>
Expand Down Expand Up @@ -243,6 +246,13 @@ where
}
}
}

fn anyhow(self) -> anyhow::Result<T>
where
E: Into<anyhow::Error>,
{
self.map_err(Into::into)
}
}

fn log_error_with_caller<E>(caller: core::panic::Location<'_>, error: E, level: log::Level)
Expand Down

0 comments on commit ac07b91

Please sign in to comment.