From 1bfc330000d121febf8fca485e3bafe7df7d52cb Mon Sep 17 00:00:00 2001 From: h7x4 Date: Wed, 24 Jun 2026 12:50:19 +0900 Subject: [PATCH] {finger,ruptime,rwho}: render nicer varlink errors for users --- src/bin/finger.rs | 14 ++++++++++++-- src/bin/ruptime.rs | 17 +++++++++++++++-- src/bin/rwho.rs | 17 +++++++++++++++-- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/bin/finger.rs b/src/bin/finger.rs index 6579bd7..34e6659 100644 --- a/src/bin/finger.rs +++ b/src/bin/finger.rs @@ -5,7 +5,7 @@ use roowho2_lib::{ proto::finger_protocol::FingerResponseUserEntry, server::{ fingerd::{FingerRequestInfo, FingerRequestNetworking}, - varlink_api::VarlinkFingerClientProxy, + varlink_api::{VarlinkFingerClientError, VarlinkFingerClientProxy}, }, }; @@ -196,7 +196,17 @@ async fn main() -> anyhow::Result<()> { ) .await .context("Failed to send finger request")? - .map_err(|e| anyhow::anyhow!("Server returned an error for finger request: {:?}", e))?; + .map_err(|e| match e { + VarlinkFingerClientError::Disabled => { + anyhow::anyhow!("The fingerd service is disabled on the server") + } + VarlinkFingerClientError::TimedOut => { + anyhow::anyhow!("The fingerd service timed out while processing the request") + } + VarlinkFingerClientError::InvalidRequest => { + anyhow::anyhow!("The fingerd service could not process the request, please check the logs or report the error to your system administrators") + } + })?; if args.json { println!("{}", serde_json::to_string_pretty(&reply).unwrap()); diff --git a/src/bin/ruptime.rs b/src/bin/ruptime.rs index 1e84ac0..b30e598 100644 --- a/src/bin/ruptime.rs +++ b/src/bin/ruptime.rs @@ -3,7 +3,10 @@ use chrono::{Duration, Utc}; use clap::{CommandFactory, Parser}; use clap_complete::{Shell, generate}; -use roowho2_lib::{proto::WhodStatusUpdate, server::varlink_api::VarlinkRwhodClientProxy}; +use roowho2_lib::{ + proto::WhodStatusUpdate, + server::varlink_api::{VarlinkRwhodClientError, VarlinkRwhodClientProxy}, +}; /// Show host status of local machines. /// @@ -70,7 +73,17 @@ async fn main() -> anyhow::Result<()> { .ruptime(args.all) .await .context("Failed to send rwho request")? - .map_err(|e| anyhow::anyhow!("Server returned an error for rwho request: {:?}", e))?; + .map_err(|e| match e { + VarlinkRwhodClientError::Disabled => { + anyhow::anyhow!("The rwhod service is disabled on the server") + } + VarlinkRwhodClientError::TimedOut => { + anyhow::anyhow!("The rwhod service timed out while processing the request") + } + VarlinkRwhodClientError::InvalidRequest => { + anyhow::anyhow!("The rwhod service could not process the request, please check the logs or report the error to your system administrators") + } + })?; sort_entries(&mut reply, args.load, args.time, args.users, args.reverse); diff --git a/src/bin/rwho.rs b/src/bin/rwho.rs index 0bec362..59b97ef 100644 --- a/src/bin/rwho.rs +++ b/src/bin/rwho.rs @@ -1,7 +1,10 @@ use anyhow::Context; use clap::{CommandFactory, Parser}; use clap_complete::{Shell, generate}; -use roowho2_lib::{proto::WhodUserEntry, server::varlink_api::VarlinkRwhodClientProxy}; +use roowho2_lib::{ + proto::WhodUserEntry, + server::varlink_api::{VarlinkRwhodClientError, VarlinkRwhodClientProxy}, +}; /// Check who is logged in on local machines. /// @@ -50,7 +53,17 @@ async fn main() -> anyhow::Result<()> { .rwho(args.all) .await .context("Failed to send rwho request")? - .map_err(|e| anyhow::anyhow!("Server returned an error for rwho request: {:?}", e))?; + .map_err(|e| match e { + VarlinkRwhodClientError::Disabled => { + anyhow::anyhow!("The rwhod service is disabled on the server") + } + VarlinkRwhodClientError::TimedOut => { + anyhow::anyhow!("The rwhod service timed out while processing the request") + } + VarlinkRwhodClientError::InvalidRequest => { + anyhow::anyhow!("The rwhod service could not process the request, please check the logs or report the error to your system administrators") + } + })?; reply.sort_by(|(host, user), (host2, user2)| { user.user_id