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

paulk pushed a commit to branch GROOVY_5_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_5_0_X by this push:
     new 4d3fcac30b minor refactor: ignore exception with /slurp
4d3fcac30b is described below

commit 4d3fcac30b4763181fd5f2f68e1aa81311d0e8ca
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Sep 5 00:04:22 2025 +1000

    minor refactor: ignore exception with /slurp
---
 .../groovy/groovysh/jline/GroovyCommands.groovy    | 25 ++++++++++++++++------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git 
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyCommands.groovy
 
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyCommands.groovy
index 13cfa9a8d0..75929369e0 100644
--- 
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyCommands.groovy
+++ 
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyCommands.groovy
@@ -371,8 +371,12 @@ class GroovyCommands extends JlineCommandRegistry 
implements CommandRegistry {
             throw new IllegalArgumentException("Invalid parameter type: " + 
arg.getClass().simpleName)
         }
         try {
-            Path path = workDir.get().resolve(arg)
-            if (Files.exists(path)) {
+//            NamedInputStream nis = getSource(arg, input.xargs(), 
input.args().toList())
+            Path path = null
+            try {
+                path = workDir.get().resolve(arg)
+            } catch(Exception ignore) { }
+            if (path && Files.exists(path)) {
                 if (!format) {
                     def ext = path.extension
                     if (ext.equalsIgnoreCase('json')) {
@@ -402,11 +406,7 @@ class GroovyCommands extends JlineCommandRegistry 
implements CommandRegistry {
                     def parser = getParser(format, slurpers[format])
                     out = parser.parse(path)
                 } else if (format == 'CSV') {
-                    def parserName = 'org.apache.commons.csv.CSVFormat'
-                    if (!ClassUtils.lookFor(engine, parserName)) {
-                        throw new IllegalArgumentException("$format format 
requires $parserName to be available")
-                    }
-                    def parser = 
engine.execute("${parserName}.DEFAULT.builder().setHeader().setSkipHeaderRecord(true).build()")
+                    def parser = getCsvParser(format)
                     out = 
parser.parse(path.newReader(encoding.displayName())).toList()*.toMap()
                 } else if (format == 'PROPERTIES') {
                     out = path.withInputStream{ is ->
@@ -423,6 +423,9 @@ class GroovyCommands extends JlineCommandRegistry 
implements CommandRegistry {
                 } else if (format in slurpers.keySet()) {
                     def parser = getParser(format, slurpers[format])
                     out = parser.parseText(arg)
+                } else if (format == 'CSV') {
+                    def parser = getCsvParser(format)
+                    out = parser.parse(new StringReader(arg)).toList()*.toMap()
                 } else {
                     out = engine.deserialize(arg, 'NONE')
                 }
@@ -434,6 +437,14 @@ class GroovyCommands extends JlineCommandRegistry 
implements CommandRegistry {
         out
     }
 
+    private getCsvParser(String format) {
+        def parserName = 'org.apache.commons.csv.CSVFormat'
+        if (!ClassUtils.lookFor(engine, parserName)) {
+            throw new IllegalArgumentException("$format format requires 
$parserName to be available")
+        }
+        
engine.execute("${parserName}.DEFAULT.builder().setHeader().setSkipHeaderRecord(true).build()")
+    }
+
     Object getParser(String format, String parserName) {
         if (!ClassUtils.lookFor(parserName)) {
             throw new IllegalArgumentException("$format format requires 
$parserName to be available")

Reply via email to