This is an automated email from the ASF dual-hosted git repository.

olabusayo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git


The following commit(s) were added to refs/heads/main by this push:
     new 87ecda40f Fix Missing File Exception
87ecda40f is described below

commit 87ecda40f9bedb8641a5c650cc946dd59e03ca03
Author: olabusayoT <[email protected]>
AuthorDate: Tue Oct 15 20:52:28 2024 -0400

    Fix Missing File Exception
    
    - currently we don't capture NoSuchFileException from Paths.get in our run 
try/catch, which results in a "This is a bug" exception. With this fix, we 
capture the exception and add a bit more detail to make it clear what is 
happening (missing file or directory), since the exception only reports the 
file name.
    - add cli test
    
    DAFFODIL-2944
---
 .../src/main/scala/org/apache/daffodil/cli/Main.scala         |  4 ++++
 .../org/apache/daffodil/cli/cliTest/TestCLIParsing.scala      | 11 +++++++++++
 2 files changed, 15 insertions(+)

diff --git a/daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala 
b/daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala
index ba35a4306..846b43a28 100644
--- a/daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala
+++ b/daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala
@@ -2005,6 +2005,10 @@ class Main(
           Logger.log.error(Misc.getSomeMessage(e).get)
           ExitCode.FileNotFound
         }
+        case e: java.nio.file.NoSuchFileException => {
+          Logger.log.error(Misc.getSomeMessage(e).get + " (No such file or 
directory)")
+          ExitCode.FileNotFound
+        }
         case e: ExternalVariableException => {
           Logger.log.error(Misc.getSomeMessage(e).get)
           ExitCode.BadExternalVariable
diff --git 
a/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/TestCLIParsing.scala
 
b/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/TestCLIParsing.scala
index 1df8726f2..51eb67061 100644
--- 
a/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/TestCLIParsing.scala
+++ 
b/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/TestCLIParsing.scala
@@ -271,6 +271,17 @@ class TestCLIParsing {
     }(ExitCode.Success)
   }
 
+  @Test def test_CLI_Parsing_SimpleParse_inFileDoesNotExist(): Unit = {
+    val schema = path(
+      
"daffodil-test/src/test/resources/org/apache/daffodil/section06/entities/charClassEntities.dfdl.xsd"
+    )
+    val input = path("/does/not/exist/input.txt")
+
+    runCLI(args"parse -s $schema -r matrix $input") { cli =>
+      cli.expectErr(s"[error] $input (No such file or directory)")
+    }(ExitCode.FileNotFound)
+  }
+
   @Test def test_CLI_Parsing_SimpleParse_stOutDash(): Unit = {
     val schema = path(
       
"daffodil-test/src/test/resources/org/apache/daffodil/section06/entities/charClassEntities.dfdl.xsd"

Reply via email to