From f568ac111db1b1dfe3896a2b8474e0d0edae491e Mon Sep 17 00:00:00 2001 From: candifloss Date: Fri, 27 Sep 2024 15:29:14 +0530 Subject: [PATCH] error handling --- src/formats/rson.rs | 5 +++-- src/main.rs | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/formats/rson.rs b/src/formats/rson.rs index 4609941..fd4027d 100644 --- a/src/formats/rson.rs +++ b/src/formats/rson.rs @@ -1,9 +1,10 @@ // This module deals with converting the notification object into rson format, which can be used instead of json if preferred use crate::notification::Notification; use rson_rs::ser::to_string as rson_string; +use rson_rs::de::Error as RsonError; impl Notification { - pub fn rson(&self) -> Result { - rson_string(self).map_err(|e| format!("Failed to serialize to RSON: {}", e)) + pub fn rson(&self) -> Result { + rson_string(self).map_err(|e| RsonError::Message(format!("RSON serialization error: {}", e))) } } diff --git a/src/main.rs b/src/main.rs index 5a8b329..bdf9847 100644 --- a/src/main.rs +++ b/src/main.rs @@ -132,7 +132,11 @@ async fn main() -> Result<()> { println!("{}", ¬if.json()); // Print the json version } "r" => { - println!("{}", ¬if.rson()); // Print the rson version + // Print the rson version + match notif.rson() { + Ok(rson_string) => println!("{}", rson_string), + Err(e) => eprintln!("Failed to convert to RSON: {}", e), + } } "p" => { println!("{}\n", ¬if.plain()); // Print the plain version