Repository: crate-ci/typos (rust)

Issue:
typos-cli Crash Report
name = 'typos-cli'
operating_system = 'windows'
crate_version = '1.0.5'
explanation = '''
Panic occurred in file 'C:\Users\brian\.cargo\registry\src\github.com-1ecc6299db9ec823\typos-cli-1.0.5\src\policy.rs' at line 90
'''
cause = '`walk()` should be called first'
method = 'Panic'
backtrace = '''

   0: 0x7ff7059f4f79 - <unresolved>
   1: 0x7ff705a1a1e0 - <unresolved>
   2: 0x7ff705a1a032 - <unresolved>
   3: 0x7ff7058a68b3 - <unresolved>
   4: 0x7ff7058b071e - <unresolved>
   5: 0x7ff7058a5b64 - <unresolved>
   6: 0x7ff7058ecd9d - <unresolved>
   7: 0x7ff7058ede8f - <unresolved>
   8: 0x7ff7058f56c4 - <unresolved>
   9: 0x7ff7058f032f - <unresolved>
  10: 0x7ff7058f55e9 - <unresolved>
  11: 0x7ff7059f850a - <unresolved>
  12: 0x7fffb9f37034 - BaseThreadInitThunk
  13: 0x7fffba122651 - RtlUserThreadStart'''



Pull request description:
fix(cli): Don't panic
Fixes #277

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9156b7d..c024c70 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
 <!-- next-header -->
 ## [Unreleased] - ReleaseDate
 
+#### Bug Fixes
+
+- Fix the prior `typos <file>` fix that broke all other forms
+- Extend the fix to other modes (`--dump-config`, etc)
+
 ## [1.0.5] - 2021-06-05
 
 #### Bug Fixes
diff --git a/src/bin/typos-cli/main.rs b/src/bin/typos-cli/main.rs
index 8667b89..ecbdfdd 100644
--- a/src/bin/typos-cli/main.rs
+++ b/src/bin/typos-cli/main.rs
@@ -66,11 +66,13 @@ fn run_dump_config(args: &args::Args, output_path: &std::path::Path) -> proc_exi
 
     let path = &args.path[0];
     let cwd = if path == std::path::Path::new("-") {
-        global_cwd.as_path()
+        global_cwd
     } else if path.is_file() {
-        path.parent().unwrap()
+        let mut cwd = path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
+        cwd.pop();
+        cwd
     } else {
-        path.as_path()
+        path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?
     };
     let cwd = cwd.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
 
@@ -108,11 +110,13 @@ fn run_type_list(args: &args::Args) -> proc_exit::ExitResult {
 
     let path = &args.path[0];
     let cwd = if path == std::path::Path::new("-") {
-        global_cwd.as_path()
+        global_cwd
     } else if path.is_file() {
-        path.parent().unwrap()
+        let mut cwd = path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
+        cwd.pop();
+        cwd
     } else {
-        path.as_path()
+        path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?
     };
     let cwd = cwd.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
 
@@ -178,7 +182,7 @@ fn run_checks(
             cwd.pop();
             cwd
         } else {
-            path.clone()
+            path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?
         };
 
         engine


Test patch:
diff --git a/tests/cli.rs b/tests/cli.rs
index 9fcc0cd..e0fec87 100644
--- a/tests/cli.rs
+++ b/tests/cli.rs
@@ -29,3 +29,16 @@ fn test_file_failure() {
     cmd.arg("README.md");
     cmd.assert().code(2);
 }
+
+#[test]
+fn test_relative_dir_failure() {
+    let mut cmd = Command::cargo_bin("typos").unwrap();
+    cmd.arg(".");
+    cmd.assert().code(2);
+}
+
+#[test]
+fn test_assumed_dir_failure() {
+    let mut cmd = Command::cargo_bin("typos").unwrap();
+    cmd.assert().code(2);
+}