Author: olga
Date: Thu Jul 17 16:07:24 2008
New Revision: 677771

URL: http://svn.apache.org/viewvc?rev=677771&view=rev
Log:
PIG-172: permission error handling

Added:
    incubator/pig/branches/types/src/org/apache/pig/tools/grunt/Utils.java
Modified:
    incubator/pig/branches/types/src/org/apache/pig/tools/grunt/Grunt.java
    incubator/pig/branches/types/src/org/apache/pig/tools/grunt/GruntParser.java

Modified: incubator/pig/branches/types/src/org/apache/pig/tools/grunt/Grunt.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/tools/grunt/Grunt.java?rev=677771&r1=677770&r2=677771&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/tools/grunt/Grunt.java 
(original)
+++ incubator/pig/branches/types/src/org/apache/pig/tools/grunt/Grunt.java Thu 
Jul 17 16:07:24 2008
@@ -56,10 +56,12 @@
         try {
             parser.setInteractive(false);
             parser.parseStopOnError();
-        } catch (Throwable e) {
-            log.error(e);
-            throw e;
-        }
+        } catch (Exception e) {
+            Exception pe = Utils.getPermissionException(e);
+            if (pe != null)
+                log.error("You don't have permission to perform the operation. 
Error from the server: " + pe.getMessage());
     
+            throw (e);
+        } 
     }
 }

Modified: 
incubator/pig/branches/types/src/org/apache/pig/tools/grunt/GruntParser.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/tools/grunt/GruntParser.java?rev=677771&r1=677770&r2=677771&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/tools/grunt/GruntParser.java 
(original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/tools/grunt/GruntParser.java 
Thu Jul 17 16:07:24 2008
@@ -23,6 +23,8 @@
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Properties;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -88,7 +90,17 @@
             }
             catch(Exception e)
             {
-                log.error(e.getMessage());
+                Exception pe = Utils.getPermissionException(e);
+                if (pe != null)
+                    log.error("You don't have permission to perform the 
operation. Error from the server: " + pe.getMessage());
+                else {
+                    ByteArrayOutputStream bs = new ByteArrayOutputStream();
+                    e.printStackTrace(new PrintStream(bs));
+                    log.error(bs.toString());
+                    log.error(e.getMessage());
+                    log.error(e);
+               }
+
             }
     }
 

Added: incubator/pig/branches/types/src/org/apache/pig/tools/grunt/Utils.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/tools/grunt/Utils.java?rev=677771&view=auto
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/tools/grunt/Utils.java 
(added)
+++ incubator/pig/branches/types/src/org/apache/pig/tools/grunt/Utils.java Thu 
Jul 17 16:07:24 2008
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pig.tools.grunt;
+
+class Utils {
+    static Exception getPermissionException(Exception top){
+        Throwable current = top;
+
+        while (current != null && (current.getMessage() == null || 
current.getMessage().indexOf("Permission denied") == -1)){
+            current = current.getCause();
+        }
+        return (Exception)current;
+    }
+}
+


Reply via email to