You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/01/05 23:55:13 UTC

[41/50] incubator-tinkerpop git commit: Better error reporting around gremlin.sh init script.

Better error reporting around gremlin.sh init script.

Refactored code a bit to catch exceptions related to IO on the init script itself versus errors in line of code evaluation. Not sure how to write tests here since we call System.exit(1) on error.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/1f6cb945
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/1f6cb945
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/1f6cb945

Branch: refs/heads/TINKERPOP-1033
Commit: 1f6cb945c5ed0171a502c6468a648e8063fa1bef
Parents: a705c21
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Dec 29 13:41:22 2015 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Dec 29 13:42:44 2015 -0500

----------------------------------------------------------------------
 .../tinkerpop/gremlin/console/Console.groovy    | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1f6cb945/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index acf613f..5479360 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -282,19 +282,21 @@ class Console {
     }
 
     private void initializeShellWithScript(final String initScriptFile) {
-        String line = ""
         try {
-            final BufferedReader reader = new BufferedReader(new InputStreamReader(
-                    new FileInputStream(initScriptFile), Charset.forName("UTF-8")))
-            while ((line = reader.readLine()) != null) {
-                groovy.execute(line)
+            final File file = new File(initScriptFile)
+            file.eachLine { line ->
+                try {
+                    groovy.execute(line)
+                } catch (Exception ex) {
+                    io.err.println("Bad line in Gremlin initialization file at [$line] - ${ex.message}")
+                    System.exit(1)
+                }
             }
-            reader.close()
         } catch (FileNotFoundException ignored) {
-            io.err.println(String.format("Gremlin initialization file not found at [%s].", initScriptFile))
+            io.err.println("Gremlin initialization file not found at [$initScriptFile].")
             System.exit(1)
-        } catch (IOException ignored) {
-            io.err.println(String.format("Bad line in Gremlin initialization file at [%s].", line))
+        } catch (Exception ex) {
+            io.err.println("Error starting Gremlin with initialization script at [$initScriptFile] - ${ex.message}")
             System.exit(1)
         }
     }