Skip to content

Commit

Permalink
fix error handling in wm_info_provider
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxVerevkin committed Oct 13, 2024
1 parent 2febf20 commit 7ff4f07
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn main() -> anyhow::Result<()> {
.unwrap()
.child
.kill();
ctx.state.set_error(ctx.conn, e);
ctx.state.set_error(ctx.conn, "status", e);
Ok(event_loop::Action::Unregister)
}
}
Expand Down
19 changes: 12 additions & 7 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct State {
pub pending_outputs: Vec<PendingOutput>,

pub hidden: bool,
pub has_error: bool,
pub bars: Vec<Bar>,

pub shared_state: SharedState,
Expand Down Expand Up @@ -99,6 +100,7 @@ impl State {
.collect(),

hidden: false,
has_error: false,
bars: Vec::new(),

shared_state: SharedState {
Expand All @@ -114,27 +116,30 @@ impl State {
};

if let Err(e) = error {
this.set_error(conn, e.to_string());
this.set_error(conn, "init", e.to_string());
}

this
}

pub fn set_blocks(&mut self, conn: &mut Connection<Self>, blocks: Vec<Block>) {
self.shared_state
.blocks_cache
.process_new_blocks(&self.shared_state.config, blocks);
self.draw_all(conn);
if !self.has_error {
self.shared_state
.blocks_cache
.process_new_blocks(&self.shared_state.config, blocks);
self.draw_all(conn);
}
}

pub fn set_error(&mut self, conn: &mut Connection<Self>, error: impl Display) {
pub fn set_error(&mut self, conn: &mut Connection<Self>, context: &str, error: impl Display) {
self.set_blocks(
conn,
vec![Block {
full_text: error.to_string(),
full_text: format!("{context}: {error}"),
..Default::default()
}],
);
self.has_error = true;
}

pub fn draw_all(&mut self, conn: &mut Connection<Self>) {
Expand Down
2 changes: 1 addition & 1 deletion src/wm_info_provider/hyprland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl WmInfoProvider for HyprlandInfoProvider {
match hyprland_cb(ctx.conn, ctx.state) {
Ok(()) => Ok(event_loop::Action::Keep),
Err(e) => {
ctx.state.set_error(ctx.conn, e);
ctx.state.set_error(ctx.conn, "hyprland", e);
Ok(event_loop::Action::Unregister)
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/wm_info_provider/river.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ fn seat_status_cb(ctx: EventCtx<State, ZriverSeatStatusV1>) {

fn river_command_cb(ctx: EventCtx<State, ZriverCommandCallbackV1>) {
if let zriver_command_callback_v1::Event::Failure(msg) = ctx.event {
ctx.state.set_error(ctx.conn, msg.to_string_lossy())
ctx.state
.set_error(ctx.conn, "river", msg.to_string_lossy())
}
}

0 comments on commit 7ff4f07

Please sign in to comment.