diff --git a/Cargo.toml b/Cargo.toml index 00fe0ef..1d9e560 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,4 +24,5 @@ anyhow = "*" deadpool = "*" async-trait = "*" thiserror = "*" -semver = "*" \ No newline at end of file +semver = "*" +color-eyre = "0.6.2" \ No newline at end of file diff --git a/src/daemon_backend.rs b/src/daemon_backend.rs index 698edbd..e451c51 100644 --- a/src/daemon_backend.rs +++ b/src/daemon_backend.rs @@ -19,12 +19,13 @@ impl ObjectBackend for DaemonConnectionPool { async fn object_operation + Debug>( &self, object: O, - operation: D, + operation: &str, + payload: D, ) -> Result> { let message = GiteratedMessage { object, - operation: D::operation_name().to_string(), - payload: operation, + operation: operation.to_string(), + payload, }; let mut connection = self @@ -93,8 +94,24 @@ async fn send_expect< } }; - let _as_target = serde_json::from_slice::(&payload) + let raw_result = bincode::deserialize::, OperationError>>>(&payload) .map_err(|e| OperationError::Internal(e.to_string()))?; + + // Map ok + let raw_result = match raw_result { + Ok(raw) => Ok(serde_json::from_slice(&raw) + .map_err(|e| OperationError::Internal(e.to_string()))?), + Err(err) => Err(match err { + OperationError::Operation(err) => OperationError::Operation( + serde_json::from_slice(&err) + .map_err(|e| OperationError::Internal(e.to_string()))?, + ), + OperationError::Internal(err) => OperationError::Internal(err), + OperationError::Unhandled => OperationError::Unhandled, + }), + }; + + return raw_result; } panic!() diff --git a/src/main.rs b/src/main.rs index 00211a5..20abf8e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,9 +7,14 @@ use giterated_models::{ user::{DisplayName, User}, }; +use color_eyre::eyre::Result; +use tracing::info; + #[tokio::main] -async fn main() -> Result<(), anyhow::Error> { +async fn main() -> Result<()> { tracing_subscriber::fmt::init(); + color_eyre::install()?; + let pool = DaemonConnectionPool::connect_other( Instance::from_str("giterated.dev")?, ("127.0.0.1:1111").parse().unwrap(), @@ -18,11 +23,17 @@ async fn main() -> Result<(), anyhow::Error> { let mut user = pool.get_object::("ambee:giterated.dev").await?; - let _display_name = user.get::().await?; + info!("Getting display name for {}!", user); + + let display_name = user.get::().await?; - let _repositories = user + info!("{}'s display name is {}", user, display_name); + + let repositories = user .repositories(&Instance::from_str("giterated.dev").unwrap()) .await?; + info!("Repository: {:#?}", repositories); + Ok(()) }