diff options
author | Ben Morrison <ben@gbmor.dev> | 2020-05-26 23:15:51 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2020-05-26 23:54:14 -0400 |
commit | 841e6a34a49261d2681c8a4d2c1dc176ba4e3b35 (patch) | |
tree | 726d6f77657ea79740a32c0ae55db88242591172 /src/posts.rs | |
parent | 8ecc2943a4241d466a9bf5a359260a958e3d3b46 (diff) | |
download | clinte-841e6a34a49261d2681c8a4d2c1dc176ba4e3b35.tar.gz |
removed panics and refactored error handling
Using a helper function to handle fatal errors error::helper() Displays the simplified message if an error condition occurs. Displays both the simplified and the raw error message if -v verbose logging is enabled.
Diffstat (limited to 'src/posts.rs')
-rw-r--r-- | src/posts.rs | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/posts.rs b/src/posts.rs index e019454..be95533 100644 --- a/src/posts.rs +++ b/src/posts.rs @@ -38,8 +38,10 @@ pub fn create(db: &db::Conn) -> error::Result<()> { println!(); println!("Title of the new post: "); + let mut title = String::new(); io::stdin().read_line(&mut title)?; + let title = str_to_utf8(title.trim()); let title = if title.len() > 30 { &title[..30] @@ -48,6 +50,7 @@ pub fn create(db: &db::Conn) -> error::Result<()> { }; println!(); + let body_raw = str_to_utf8(&ed::call()); let body = if body_raw.len() > 500 { &body_raw[..500] |