mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-12 17:32:21 -04:00
error: Split out error utils into a separate module
This commit is contained in:
parent
f4247de8c1
commit
fd500229d6
5 changed files with 29 additions and 18 deletions
23
src/error.rs
Normal file
23
src/error.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright © 2023 Collabora Ltd.
|
||||
* Copyright © 2024 Valve Software
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
use zbus::fdo;
|
||||
|
||||
pub fn to_zbus_fdo_error<S: ToString>(error: S) -> fdo::Error {
|
||||
fdo::Error::Failed(error.to_string())
|
||||
}
|
||||
|
||||
pub fn to_zbus_error<S: ToString>(error: S) -> zbus::Error {
|
||||
zbus::Error::Failure(error.to_string())
|
||||
}
|
||||
|
||||
pub fn zbus_to_zbus_fdo(error: zbus::Error) -> fdo::Error {
|
||||
match error {
|
||||
zbus::Error::FDO(error) => *error,
|
||||
error => fdo::Error::Failed(error.to_string()),
|
||||
}
|
||||
}
|
16
src/lib.rs
16
src/lib.rs
|
@ -17,6 +17,7 @@ use tracing::{info, warn};
|
|||
mod cec;
|
||||
mod daemon;
|
||||
mod ds_inhibit;
|
||||
mod error;
|
||||
mod hardware;
|
||||
mod manager;
|
||||
mod power;
|
||||
|
@ -135,21 +136,6 @@ async fn reload() -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn to_zbus_fdo_error<S: ToString>(error: S) -> zbus::fdo::Error {
|
||||
zbus::fdo::Error::Failed(error.to_string())
|
||||
}
|
||||
|
||||
pub fn to_zbus_error<S: ToString>(error: S) -> zbus::Error {
|
||||
zbus::Error::Failure(error.to_string())
|
||||
}
|
||||
|
||||
pub fn zbus_to_zbus_fdo(error: zbus::Error) -> zbus::fdo::Error {
|
||||
match error {
|
||||
zbus::Error::FDO(error) => *error,
|
||||
error => zbus::fdo::Error::Failed(error.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::testing;
|
||||
|
|
|
@ -12,6 +12,7 @@ use tracing::error;
|
|||
use zbus::zvariant::Fd;
|
||||
use zbus::{interface, Connection, SignalContext};
|
||||
|
||||
use crate::error::{to_zbus_error, to_zbus_fdo_error};
|
||||
use crate::hardware::{check_support, variant, FanControl, FanControlState, HardwareVariant};
|
||||
use crate::power::{
|
||||
get_gpu_clocks, get_gpu_performance_level, get_tdp_limit, set_gpu_clocks,
|
||||
|
@ -22,7 +23,7 @@ use crate::wifi::{
|
|||
get_wifi_backend, get_wifi_power_management_state, set_wifi_backend, set_wifi_debug_mode,
|
||||
set_wifi_power_management_state, WifiBackend, WifiDebugMode, WifiPowerManagement,
|
||||
};
|
||||
use crate::{to_zbus_error, to_zbus_fdo_error, API_VERSION};
|
||||
use crate::API_VERSION;
|
||||
|
||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||
#[repr(u32)]
|
||||
|
|
|
@ -17,7 +17,7 @@ use tokio::process::{Child, Command};
|
|||
use tracing::error;
|
||||
use zbus::interface;
|
||||
|
||||
use crate::to_zbus_fdo_error;
|
||||
use crate::error::to_zbus_fdo_error;
|
||||
|
||||
const PROCESS_PREFIX: &str = "/com/steampowered/SteamOSManager1/Process";
|
||||
|
||||
|
|
|
@ -13,7 +13,8 @@ use zbus::zvariant::Fd;
|
|||
use zbus::{interface, Connection, Proxy, SignalContext};
|
||||
|
||||
use crate::cec::{HdmiCecControl, HdmiCecState};
|
||||
use crate::{to_zbus_error, to_zbus_fdo_error, zbus_to_zbus_fdo, API_VERSION};
|
||||
use crate::error::{to_zbus_error, to_zbus_fdo_error, zbus_to_zbus_fdo};
|
||||
use crate::API_VERSION;
|
||||
|
||||
macro_rules! method {
|
||||
($self:expr, $method:expr, $($args:expr),+) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue