anyhow context is nice

This commit is contained in:
galister
2025-12-10 21:03:13 +09:00
parent 7c41a01122
commit c4b8fbd579
8 changed files with 29 additions and 25 deletions

View File

@@ -1,6 +1,6 @@
use std::{fs::File, io::Read}; use std::{fs::File, io::Read};
use anyhow::bail; use anyhow::{bail, Context};
use json::{array, object}; use json::{array, object};
use ovr_overlay::applications::ApplicationsManager; use ovr_overlay::applications::ApplicationsManager;
@@ -18,7 +18,7 @@ pub(super) fn install_manifest(app_mgr: &mut ApplicationsManager) -> anyhow::Res
Ok(ref path) => path, Ok(ref path) => path,
Err(_) => executable_pathbuf Err(_) => executable_pathbuf
.to_str() .to_str()
.ok_or_else(|| anyhow::anyhow!("Invalid executable path"))?, .context("Invalid executable path")?,
}; };
if app_mgr.is_application_installed(APP_KEY) == Ok(true) if app_mgr.is_application_installed(APP_KEY) == Ok(true)

View File

@@ -6,7 +6,7 @@ use crate::backend::wayvr::egl_ex::{
}; };
use super::egl_ex; use super::egl_ex;
use anyhow::anyhow; use anyhow::{anyhow, Context};
#[derive(Debug)] #[derive(Debug)]
pub struct EGLData { pub struct EGLData {
@@ -83,9 +83,9 @@ fn get_disp(
egl egl
.get_display(khronos_egl::DEFAULT_DISPLAY) .get_display(khronos_egl::DEFAULT_DISPLAY)
.ok_or_else(|| anyhow!( .context(
"Both eglGetPlatformDisplayEXT and eglGetDisplay failed. This shouldn't happen unless you don't have any display manager running. Cannot continue, check your EGL installation." "Both eglGetPlatformDisplayEXT and eglGetDisplay failed. This shouldn't happen unless you don't have any display manager running. Cannot continue, check your EGL installation."
)) )
} }
} }
@@ -113,7 +113,7 @@ impl EGLData {
let config = egl let config = egl
.choose_first_config(display, &attrib_list)? .choose_first_config(display, &attrib_list)?
.ok_or_else(|| anyhow!("Failed to get EGL config"))?; .context("Failed to get EGL config")?;
egl.bind_api(khronos_egl::OPENGL_ES_API)?; egl.bind_api(khronos_egl::OPENGL_ES_API)?;

View File

@@ -10,6 +10,7 @@ pub mod server_ipc;
mod smithay_wrapper; mod smithay_wrapper;
mod time; mod time;
mod window; mod window;
use anyhow::Context;
use comp::Application; use comp::Application;
use display::{Display, DisplayInitParams, DisplayVec}; use display::{Display, DisplayInitParams, DisplayVec};
use event_queue::SyncEventQueue; use event_queue::SyncEventQueue;
@@ -20,9 +21,9 @@ use smallvec::SmallVec;
use smithay::{ use smithay::{
backend::{ backend::{
egl, egl,
renderer::{ImportDma, gles::GlesRenderer}, renderer::{gles::GlesRenderer, ImportDma},
}, },
input::{SeatState, keyboard::XkbConfig}, input::{keyboard::XkbConfig, SeatState},
output::{Mode, Output}, output::{Mode, Output},
reexports::wayland_server::{self, backend::ClientId}, reexports::wayland_server::{self, backend::ClientId},
wayland::{ wayland::{
@@ -44,7 +45,7 @@ use wayvr_ipc::{packet_client, packet_server};
use crate::{ use crate::{
state::AppState, state::AppState,
subsystem::hid::{MODS_TO_KEYS, WheelDelta}, subsystem::hid::{WheelDelta, MODS_TO_KEYS},
}; };
const STR_INVALID_HANDLE_DISP: &str = "Invalid display handle"; const STR_INVALID_HANDLE_DISP: &str = "Invalid display handle";
@@ -283,7 +284,7 @@ impl WayVR {
.state .state
.displays .displays
.get_mut(&display) .get_mut(&display)
.ok_or_else(|| anyhow::anyhow!(STR_INVALID_HANDLE_DISP))?; .context(STR_INVALID_HANDLE_DISP)?;
/* Buffer warm-up is required, always two first calls of this function are always rendered */ /* Buffer warm-up is required, always two first calls of this function are always rendered */
if !display.wants_redraw && display.rendered_frame_count >= 2 { if !display.wants_redraw && display.rendered_frame_count >= 2 {
@@ -695,7 +696,7 @@ impl WayVRState {
let display = self let display = self
.displays .displays
.get_mut(&display_handle) .get_mut(&display_handle)
.ok_or_else(|| anyhow::anyhow!(STR_INVALID_HANDLE_DISP))?; .context(STR_INVALID_HANDLE_DISP)?;
let res = display.spawn_process(exec_path, args, env, working_dir)?; let res = display.spawn_process(exec_path, args, env, working_dir)?;

View File

@@ -8,6 +8,7 @@ use std::{
sync::Arc, sync::Arc,
}; };
use anyhow::Context;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use wlx_common::{common::LeftRight, config::GeneralConfig, windowing::Positioning}; use wlx_common::{common::LeftRight, config::GeneralConfig, windowing::Positioning};
@@ -187,7 +188,7 @@ impl WayVRConfig {
keyboard_repeat_delay_ms: config_wayvr.keyboard_repeat_delay, keyboard_repeat_delay_ms: config_wayvr.keyboard_repeat_delay,
keyboard_repeat_rate: config_wayvr.keyboard_repeat_rate, keyboard_repeat_rate: config_wayvr.keyboard_repeat_rate,
blit_method: wayvr::BlitMethod::from_string(&config_wayvr.blit_method) blit_method: wayvr::BlitMethod::from_string(&config_wayvr.blit_method)
.ok_or_else(|| anyhow::anyhow!("Unknown blit method"))?, .context("unknown blit method")?,
auto_hide_delay: if config_wayvr.auto_hide { auto_hide_delay: if config_wayvr.auto_hide {
Some(config_wayvr.auto_hide_delay) Some(config_wayvr.auto_hide_delay)
} else { } else {

View File

@@ -4,23 +4,24 @@ use std::{
sync::Arc, sync::Arc,
}; };
use anyhow::Context;
use smallvec::SmallVec; use smallvec::SmallVec;
use vulkano::{ use vulkano::{
VulkanError, VulkanObject,
device::Device, device::Device,
format::Format, format::Format,
image::{Image, ImageCreateInfo, ImageTiling, ImageUsage, SubresourceLayout, sys::RawImage}, image::{sys::RawImage, Image, ImageCreateInfo, ImageTiling, ImageUsage, SubresourceLayout},
memory::{ memory::{
allocator::{MemoryAllocator, MemoryTypeFilter},
DedicatedAllocation, DeviceMemory, ExternalMemoryHandleType, ExternalMemoryHandleTypes, DedicatedAllocation, DeviceMemory, ExternalMemoryHandleType, ExternalMemoryHandleTypes,
MemoryAllocateInfo, MemoryImportInfo, MemoryPropertyFlags, ResourceMemory, MemoryAllocateInfo, MemoryImportInfo, MemoryPropertyFlags, ResourceMemory,
allocator::{MemoryAllocator, MemoryTypeFilter},
}, },
sync::Sharing, sync::Sharing,
VulkanError, VulkanObject,
}; };
use wgui::gfx::WGfx; use wgui::gfx::WGfx;
use wlx_capture::frame::{ use wlx_capture::frame::{
DRM_FORMAT_ABGR8888, DRM_FORMAT_ABGR2101010, DRM_FORMAT_ARGB8888, DRM_FORMAT_XBGR8888, DmabufFrame, DrmFormat, FourCC, DRM_FORMAT_ABGR2101010, DRM_FORMAT_ABGR8888,
DRM_FORMAT_XBGR2101010, DRM_FORMAT_XRGB8888, DmabufFrame, DrmFormat, FourCC, DRM_FORMAT_ARGB8888, DRM_FORMAT_XBGR2101010, DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB8888,
}; };
pub const DRM_FORMAT_MOD_INVALID: u64 = 0xff_ffff_ffff_ffff; pub const DRM_FORMAT_MOD_INVALID: u64 = 0xff_ffff_ffff_ffff;
@@ -74,7 +75,7 @@ impl WGfxDmabuf for WGfx {
..Default::default() ..Default::default()
}, },
) )
.ok_or_else(|| anyhow::anyhow!("failed to get memory type index"))?; .context("failed to get memory type index")?;
debug_assert!(self.device.enabled_extensions().khr_external_memory_fd); debug_assert!(self.device.enabled_extensions().khr_external_memory_fd);
debug_assert!(self.device.enabled_extensions().khr_external_memory); debug_assert!(self.device.enabled_extensions().khr_external_memory);

View File

@@ -1,3 +1,4 @@
use anyhow::Context;
use glam::FloatExt; use glam::FloatExt;
use wgui::{ use wgui::{
animation::{Animation, AnimationEasing}, animation::{Animation, AnimationEasing},
@@ -24,7 +25,7 @@ impl InteractLockHandler {
.state .state
.widgets .widgets
.get_as::<WidgetRectangle>(id) .get_as::<WidgetRectangle>(id)
.ok_or_else(|| anyhow::anyhow!("Element with id=\"shadow\" must be a <rectangle>"))?; .context("Element with id=\"shadow\" must be a <rectangle>")?;
Ok(Self { Ok(Self {
id, id,

View File

@@ -1,3 +1,4 @@
use anyhow::Context;
use glam::{vec3, Affine2, Affine3A, Quat, Vec3}; use glam::{vec3, Affine2, Affine3A, Quat, Vec3};
use smallvec::smallvec; use smallvec::smallvec;
use std::{cell::RefCell, collections::HashMap, rc::Rc, sync::Arc}; use std::{cell::RefCell, collections::HashMap, rc::Rc, sync::Arc};
@@ -677,7 +678,7 @@ impl OverlayBackend for WayVRBackend {
.data .data
.state .state
.get_render_data(ctx.display) .get_render_data(ctx.display)
.ok_or_else(|| anyhow::anyhow!("Failed to fetch render data"))? .context("Failed to fetch render data")?
.clone(); .clone();
drop(wayvr); drop(wayvr);

View File

@@ -1,11 +1,12 @@
use anyhow::Context;
use wlx_capture::wayland::wayland_client::{ use wlx_capture::wayland::wayland_client::{
Connection, Dispatch, Proxy, QueueHandle, globals::{registry_queue_init, GlobalListContents},
globals::{GlobalListContents, registry_queue_init},
protocol::{ protocol::{
wl_keyboard::{self, WlKeyboard}, wl_keyboard::{self, WlKeyboard},
wl_registry::WlRegistry, wl_registry::WlRegistry,
wl_seat::{self, Capability, WlSeat}, wl_seat::{self, Capability, WlSeat},
}, },
Connection, Dispatch, Proxy, QueueHandle,
}; };
use xkbcommon::xkb; use xkbcommon::xkb;
@@ -46,9 +47,7 @@ pub fn get_keymap_wl() -> anyhow::Result<XkbKeymap> {
// this gets us the wl_keyboard // this gets us the wl_keyboard
let _ = queue.blocking_dispatch(&mut me); let _ = queue.blocking_dispatch(&mut me);
me.keymap me.keymap.take().context("could not load keymap")
.take()
.ok_or_else(|| anyhow::anyhow!("Could not load keymap"))
} }
impl Dispatch<WlRegistry, GlobalListContents> for WlKeymapHandler { impl Dispatch<WlRegistry, GlobalListContents> for WlKeymapHandler {