forge
Explore
Log in

Don't you dare go Hollow

Add error messages to backend initialization

Browse files at this commit

9afd728ae98059c9405fe2430399ecb89fd1a7a9Ivan MolodetskikhParent: e51268a
src/backend/tty.rsmodified+29 -14
@@ -144,11 +144,19 @@ pub struct SurfaceDmabufFeedback {
144 }144 }
145 145
146 impl Tty {146 impl Tty {
147- pub fn new(config: Rc<RefCell<Config>>, event_loop: LoopHandle<'static, State>) -> Self {147+ pub fn new(
148- let (session, notifier) = LibSeatSession::new().unwrap();148+ config: Rc<RefCell<Config>>,
149+ event_loop: LoopHandle<'static, State>,
150+ ) -> anyhow::Result<Self> {
151+ let (session, notifier) = LibSeatSession::new().context(
152+ "Error creating a session. This might mean that you're trying to run niri on a TTY \
153+ that is already busy, for example if you're running this inside tmux that had been \
154+ originally started on a different TTY",
155+ )?;
149 let seat_name = session.seat();156 let seat_name = session.seat();
150 157
151- let udev_backend = UdevBackend::new(session.seat()).unwrap();158+ let udev_backend =
159+ UdevBackend::new(session.seat()).context("error creating a udev backend")?;
152 let udev_dispatcher = Dispatcher::new(udev_backend, move |event, _, state: &mut State| {160 let udev_dispatcher = Dispatcher::new(udev_backend, move |event, _, state: &mut State| {
153 state.backend.tty().on_udev_event(&mut state.niri, event);161 state.backend.tty().on_udev_event(&mut state.niri, event);
154 });162 });
@@ -157,7 +165,9 @@ impl Tty {
157 .unwrap();165 .unwrap();
158 166
159 let mut libinput = Libinput::new_with_udev(LibinputSessionInterface::from(session.clone()));167 let mut libinput = Libinput::new_with_udev(LibinputSessionInterface::from(session.clone()));
160- libinput.udev_assign_seat(&seat_name).unwrap();168+ libinput
169+ .udev_assign_seat(&seat_name)
170+ .map_err(|()| anyhow!("error assigning the seat to libinput"))?;
161 171
162 let input_backend = LibinputInputBackend::new(libinput.clone());172 let input_backend = LibinputInputBackend::new(libinput.clone());
163 event_loop173 event_loop
@@ -192,18 +202,23 @@ impl Tty {
192 Ok(gles)202 Ok(gles)
193 };203 };
194 let api = GbmGlesBackend::with_factory(Box::new(create_renderer));204 let api = GbmGlesBackend::with_factory(Box::new(create_renderer));
195- let gpu_manager = GpuManager::new(api).unwrap();205+ let gpu_manager = GpuManager::new(api).context("error creating the GPU manager")?;
196 206
197 let (primary_node, primary_render_node) = primary_node_from_config(&config.borrow())207 let (primary_node, primary_render_node) = primary_node_from_config(&config.borrow())
198- .unwrap_or_else(|| {208+ .ok_or(())
199- let primary_gpu_path = udev::primary_gpu(&seat_name).unwrap().unwrap();209+ .or_else(|()| {
200- let primary_node = DrmNode::from_path(primary_gpu_path).unwrap();210+ let primary_gpu_path = udev::primary_gpu(&seat_name)
211+ .context("error getting the primary GPU")?
212+ .context("couldn't find a GPU")?;
213+ let primary_node = DrmNode::from_path(primary_gpu_path)
214+ .context("error opening the primary GPU DRM node")?;
201 let primary_render_node = primary_node215 let primary_render_node = primary_node
202 .node_with_type(NodeType::Render)216 .node_with_type(NodeType::Render)
203- .unwrap()217+ .context("error getting the render node for the primary GPU")?
204- .unwrap();218+ .context("error getting the render node for the primary GPU")?;
205- (primary_node, primary_render_node)219+
206- });220+ Ok::<_, anyhow::Error>((primary_node, primary_render_node))
221+ })?;
207 222
208 let mut node_path = String::new();223 let mut node_path = String::new();
209 if let Some(path) = primary_render_node.dev_path() {224 if let Some(path) = primary_render_node.dev_path() {
@@ -213,7 +228,7 @@ impl Tty {
213 }228 }
214 info!("using as the render node: {}", node_path);229 info!("using as the render node: {}", node_path);
215 230
216- Self {231+ Ok(Self {
217 config,232 config,
218 session,233 session,
219 udev_dispatcher,234 udev_dispatcher,
@@ -227,7 +242,7 @@ impl Tty {
227 update_output_config_on_resume: false,242 update_output_config_on_resume: false,
228 ipc_outputs: Rc::new(RefCell::new(HashMap::new())),243 ipc_outputs: Rc::new(RefCell::new(HashMap::new())),
229 enabled_outputs: Arc::new(Mutex::new(HashMap::new())),244 enabled_outputs: Arc::new(Mutex::new(HashMap::new())),
230- }245+ })
231 }246 }
232 247
233 pub fn init(&mut self, niri: &mut Niri) {248 pub fn init(&mut self, niri: &mut Niri) {
src/backend/winit.rsmodified+7 -4
@@ -32,12 +32,15 @@ pub struct Winit {
32 }32 }
33 33
34 impl Winit {34 impl Winit {
35- pub fn new(config: Rc<RefCell<Config>>, event_loop: LoopHandle<State>) -> Self {35+ pub fn new(
36+ config: Rc<RefCell<Config>>,
37+ event_loop: LoopHandle<State>,
38+ ) -> Result<Self, winit::Error> {
36 let builder = WindowBuilder::new()39 let builder = WindowBuilder::new()
37 .with_inner_size(LogicalSize::new(1280.0, 800.0))40 .with_inner_size(LogicalSize::new(1280.0, 800.0))
38 // .with_resizable(false)41 // .with_resizable(false)
39 .with_title("niri");42 .with_title("niri");
40- let (backend, winit) = winit::init_from_builder(builder).unwrap();43+ let (backend, winit) = winit::init_from_builder(builder)?;
41 44
42 let output = Output::new(45 let output = Output::new(
43 "winit".to_string(),46 "winit".to_string(),
@@ -110,14 +113,14 @@ impl Winit {
110 })113 })
111 .unwrap();114 .unwrap();
112 115
113- Self {116+ Ok(Self {
114 config,117 config,
115 output,118 output,
116 backend,119 backend,
117 damage_tracker,120 damage_tracker,
118 ipc_outputs,121 ipc_outputs,
119 enabled_outputs,122 enabled_outputs,
120- }123+ })
121 }124 }
122 125
123 pub fn init(&mut self, niri: &mut Niri) {126 pub fn init(&mut self, niri: &mut Niri) {
src/main.rsmodified+2 -1
@@ -220,7 +220,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
220 event_loop.handle(),220 event_loop.handle(),
221 event_loop.get_signal(),221 event_loop.get_signal(),
222 display,222 display,
223- );223+ )
224+ .unwrap();
224 225
225 // Set WAYLAND_DISPLAY for children.226 // Set WAYLAND_DISPLAY for children.
226 let socket_name = &state.niri.socket_name;227 let socket_name = &state.niri.socket_name;
src/niri.rsmodified+7 -4
@@ -298,7 +298,7 @@ impl State {
298 event_loop: LoopHandle<'static, State>,298 event_loop: LoopHandle<'static, State>,
299 stop_signal: LoopSignal,299 stop_signal: LoopSignal,
300 display: Display<State>,300 display: Display<State>,
301- ) -> Self {301+ ) -> Result<Self, Box<dyn std::error::Error>> {
302 let _span = tracy_client::span!("State::new");302 let _span = tracy_client::span!("State::new");
303 303
304 let config = Rc::new(RefCell::new(config));304 let config = Rc::new(RefCell::new(config));
@@ -307,15 +307,18 @@ impl State {
307 env::var_os("WAYLAND_DISPLAY").is_some() || env::var_os("DISPLAY").is_some();307 env::var_os("WAYLAND_DISPLAY").is_some() || env::var_os("DISPLAY").is_some();
308 308
309 let mut backend = if has_display {309 let mut backend = if has_display {
310- Backend::Winit(Winit::new(config.clone(), event_loop.clone()))310+ let winit = Winit::new(config.clone(), event_loop.clone())?;
311+ Backend::Winit(winit)
311 } else {312 } else {
312- Backend::Tty(Tty::new(config.clone(), event_loop.clone()))313+ let tty = Tty::new(config.clone(), event_loop.clone())
314+ .context("error initializing the TTY backend")?;
315+ Backend::Tty(tty)
313 };316 };
314 317
315 let mut niri = Niri::new(config.clone(), event_loop, stop_signal, display, &backend);318 let mut niri = Niri::new(config.clone(), event_loop, stop_signal, display, &backend);
316 backend.init(&mut niri);319 backend.init(&mut niri);
317 320
318- Self { backend, niri }321+ Ok(Self { backend, niri })
319 }322 }
320 323
321 pub fn refresh_and_flush_clients(&mut self) {324 pub fn refresh_and_flush_clients(&mut self) {