Browse Source

Show proper error for invaliddownload limit/name input, change crate description

timvisee 7 years ago
parent
commit
ca0400d2e6
4 changed files with 28 additions and 13 deletions
  1. 0 5
      ROADMAP.md
  2. 4 1
      cli/Cargo.toml
  3. 14 5
      cli/src/cmd/arg/download_limit.rs
  4. 10 2
      cli/src/cmd/matcher/upload.rs

+ 0 - 5
ROADMAP.md

@@ -1,6 +1,4 @@
 # Release 0.1
 # Release 0.1
-- Print nice error in `cli/cmd/arg/download_limit.rs`
-- Resolve panics with a nice error message
 - Panic when secret is missing from URL with info action
 - Panic when secret is missing from URL with info action
 - Switch to `directories` instead of `app_dirs2`?
 - Switch to `directories` instead of `app_dirs2`?
 - Allow file/directory archiving on upload
 - Allow file/directory archiving on upload
@@ -13,9 +11,6 @@
 - Implement error handling everywhere properly
 - Implement error handling everywhere properly
 - Embed request errors
 - Embed request errors
 - Extract utility module
 - Extract utility module
-- Think of a new description:
-    Securely and easily share files from the command line;
-    a fully featured Firefox Send client. 
 - Check all TODOs, solve them when possible
 - Check all TODOs, solve them when possible
 - Windows, macOS and Redox support
 - Windows, macOS and Redox support
 
 

+ 4 - 1
cli/Cargo.toml

@@ -1,6 +1,9 @@
 [package]
 [package]
 name = "ffsend"
 name = "ffsend"
-description = "A simple Firefox Send CLI client."
+description = """\
+    Securely and easily share files from the command line.\n\
+    A fully featured Firefox Send client.\
+"""
 version = "0.0.1"
 version = "0.0.1"
 authors = ["Tim Visee <https://timvisee.com/>"]
 authors = ["Tim Visee <https://timvisee.com/>"]
 workspace = ".."
 workspace = ".."

+ 14 - 5
cli/src/cmd/arg/download_limit.rs

@@ -6,6 +6,8 @@ use ffsend_api::action::params::{
 
 
 use super::{CmdArg, CmdArgFlag, CmdArgOption};
 use super::{CmdArg, CmdArgFlag, CmdArgOption};
 
 
+use util::{ErrorHintsBuilder, quit_error_msg};
+
 /// The download limit argument.
 /// The download limit argument.
 pub struct ArgDownloadLimit { }
 pub struct ArgDownloadLimit { }
 
 
@@ -41,12 +43,19 @@ impl<'a> CmdArgOption<'a> for ArgDownloadLimit {
             .map(|d| d.parse::<u8>().expect("invalid download limit"))
             .map(|d| d.parse::<u8>().expect("invalid download limit"))
             .and_then(|d| {
             .and_then(|d| {
                 // Check the download limit bounds
                 // Check the download limit bounds
-                // TODO: print a nicely formatted error here
+                // TODO: somehow allow to force a different number here
                 if d < DOWNLOAD_MIN || d > DOWNLOAD_MAX {
                 if d < DOWNLOAD_MIN || d > DOWNLOAD_MAX {
-                    panic!(
-                        "invalid download limit, must be between {} and {}",
-                        DOWNLOAD_MIN,
-                        DOWNLOAD_MAX,
+                    quit_error_msg(
+                        format!(
+                            "invalid download limit, must be between {} and {}",
+                            DOWNLOAD_MIN,
+                            DOWNLOAD_MAX,
+                        ),
+                        ErrorHintsBuilder::default()
+                            .force(false)
+                            .verbose(false)
+                            .build()
+                            .unwrap(),
                     );
                     );
                 }
                 }
 
 

+ 10 - 2
cli/src/cmd/matcher/upload.rs

@@ -6,6 +6,7 @@ use ffsend_api::url::Url;
 
 
 use cmd::arg::{ArgDownloadLimit, ArgHost, ArgPassword, CmdArgOption};
 use cmd::arg::{ArgDownloadLimit, ArgHost, ArgPassword, CmdArgOption};
 use super::Matcher;
 use super::Matcher;
+use util::{ErrorHintsBuilder, quit_error_msg};
 
 
 /// The upload command matcher.
 /// The upload command matcher.
 pub struct UploadMatcher<'a> {
 pub struct UploadMatcher<'a> {
@@ -29,9 +30,16 @@ impl<'a: 'b, 'b> UploadMatcher<'a> {
         let name = self.matches.value_of("name")?;
         let name = self.matches.value_of("name")?;
 
 
         // The file name must not be empty
         // The file name must not be empty
+        // TODO: allow to force an empty name here, and process emtpy names on downloading
         if name.trim().is_empty() {
         if name.trim().is_empty() {
-            // TODO: return an error here
-            panic!("the new name must not be empty");
+            quit_error_msg(
+                "the file name must not be empty",
+                ErrorHintsBuilder::default()
+                    .force(false)
+                    .verbose(false)
+                    .build()
+                    .unwrap(),
+            );
         }
         }
 
 
         Some(name)
         Some(name)