You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by th...@apache.org on 2011/04/19 02:29:39 UTC

svn commit: r1094833 - in /pig/trunk: CHANGES.txt src/org/apache/pig/PigException.java src/org/apache/pig/impl/logicalLayer/schema/Schema.java src/org/apache/pig/impl/util/LogUtils.java test/org/apache/pig/test/TestPigException.java

Author: thejas
Date: Tue Apr 19 00:29:38 2011
New Revision: 1094833

URL: http://svn.apache.org/viewvc?rev=1094833&view=rev
Log:
PIG-1612: error reporting: PigException needs to have a way to indicate that
 its message is appropriate for user (laukik via thejas)

Added:
    pig/trunk/test/org/apache/pig/test/TestPigException.java
Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/PigException.java
    pig/trunk/src/org/apache/pig/impl/logicalLayer/schema/Schema.java
    pig/trunk/src/org/apache/pig/impl/util/LogUtils.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1094833&r1=1094832&r2=1094833&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Tue Apr 19 00:29:38 2011
@@ -32,6 +32,9 @@ PIG-1876: Typed map for Pig (daijy)
 
 IMPROVEMENTS
 
+PIG-1612: error reporting: PigException needs to have a way to indicate that 
+ its message is appropriate for user (laukik via thejas)
+
 PIG-1782: Add ability to load data by column family in HBaseStorage (billgraham via dvryaboy)
 
 PIG-1772: Pig 090 Documentation (chandec via olgan)

Modified: pig/trunk/src/org/apache/pig/PigException.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/PigException.java?rev=1094833&r1=1094832&r2=1094833&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/PigException.java (original)
+++ pig/trunk/src/org/apache/pig/PigException.java Tue Apr 19 00:29:38 2011
@@ -111,6 +111,7 @@ public class PigException extends IOExce
     protected byte errorSource = BUG;
     protected boolean retriable = false;
     protected String detailedMessage = null;
+    protected boolean markedAsShowToUser = false;
 
     /**
      * Create a new PigException with null as the error message.
@@ -314,7 +315,27 @@ public class PigException extends IOExce
     public void setDetailedMessage(String detailMsg) {
         detailedMessage = detailMsg;
     }
-
+    
+    /**
+     * Check if this PigException is marked as the ones whose message is to be 
+     * displayed to the user. This can be used to indicate if the corresponding 
+     * error message is a good candidate for displaying to the end user, instead
+     * of drilling down the stack trace further.
+     * @return true if this pig exception is marked as appropriate to be 
+     * displayed to the user
+     */
+    public boolean getMarkedAsShowToUser() {
+        return markedAsShowToUser;
+    }
+    
+    /**
+     * Mark this exception as a good candidate for showing its message to the 
+     * pig user 
+     */
+    public void setMarkedAsShowToUser(boolean showToUser) {
+        markedAsShowToUser = showToUser;
+    }
+    
     /**
      * Returns a short description of this throwable.
      * The result is the concatenation of:

Modified: pig/trunk/src/org/apache/pig/impl/logicalLayer/schema/Schema.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/impl/logicalLayer/schema/Schema.java?rev=1094833&r1=1094832&r2=1094833&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/impl/logicalLayer/schema/Schema.java (original)
+++ pig/trunk/src/org/apache/pig/impl/logicalLayer/schema/Schema.java Tue Apr 19 00:29:38 2011
@@ -1663,7 +1663,10 @@ public class Schema implements Serializa
                 String msg = "Error merging schema: ("  + sch + ") with " 
                 + "merged schema: (" + mergedSchema + ")" + " of schemas : "
                 + mergedSchemas;
-                throw new SchemaMergeException(msg, e);
+                SchemaMergeException sme = new SchemaMergeException(msg, 
+                        e.getErrorCode(), e);
+                sme.setMarkedAsShowToUser(true);
+                throw sme;
             }
         }
         return mergedSchema;
@@ -1833,7 +1836,7 @@ public class Schema implements Serializa
         } catch (FrontendException e) {
             String msg = "Caught exception finding FieldSchema for alias " +
             alias;
-            throw new SchemaMergeException(msg, e);
+            throw new SchemaMergeException(msg, e.getErrorCode(), e);
         }
         return fs;
     }

Modified: pig/trunk/src/org/apache/pig/impl/util/LogUtils.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/impl/util/LogUtils.java?rev=1094833&r1=1094832&r2=1094833&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/impl/util/LogUtils.java (original)
+++ pig/trunk/src/org/apache/pig/impl/util/LogUtils.java Tue Apr 19 00:29:38 2011
@@ -56,14 +56,23 @@ public class LogUtils {
         Throwable current = top;
         Throwable pigException = top;
 
+        if (current instanceof PigException && 
+                (((PigException)current).getErrorCode() != 0) && 
+                ((PigException) current).getMarkedAsShowToUser()) {
+            return (PigException) current;
+        }
         while (current != null && current.getCause() != null){
             current = current.getCause();
-            if((current instanceof PigException) && (((PigException)current).getErrorCode() != 0)) {
+            if((current instanceof PigException) && 
+                    (((PigException)current).getErrorCode() != 0)) {
                 pigException = current;
+                if (((PigException)pigException).getMarkedAsShowToUser()) {
+                    break;
+                }
             }
         }
-        return (pigException instanceof PigException? (PigException)pigException : null);
-        
+        return (pigException instanceof PigException? (PigException)pigException 
+        		: null);        
     }
     
     public static void writeLog(Throwable t, String logFileName, Log log, boolean verbose, String headerMessage) {

Added: pig/trunk/test/org/apache/pig/test/TestPigException.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestPigException.java?rev=1094833&view=auto
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPigException.java (added)
+++ pig/trunk/test/org/apache/pig/test/TestPigException.java Tue Apr 19 00:29:38 2011
@@ -0,0 +1,57 @@
+/*
+ * 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.test;
+
+import junit.framework.Assert;
+import org.apache.pig.PigException;
+import org.apache.pig.impl.util.LogUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class TestPigException {
+
+    private static final int NONZERO_ERRORCODE = 1;
+
+    @Test
+    public void testNestedException() {
+        PigException innermost = new PigException("innermost", 
+                NONZERO_ERRORCODE);
+        PigException inner = new PigException("inner", 
+                NONZERO_ERRORCODE, innermost);
+        PigException outer = new PigException("outer", 
+                NONZERO_ERRORCODE, inner);
+        Assert.assertEquals(innermost.getMessage(),
+                LogUtils.getPigException(outer).getMessage());
+    }
+
+    @Test
+    public void testStickyNestedException() {
+        PigException innermost = new PigException("innermost", 
+                NONZERO_ERRORCODE);
+        PigException inner = new PigException("inner", 
+                NONZERO_ERRORCODE, innermost);
+        inner.setMarkedAsShowToUser(true);
+        PigException outer = new PigException("outer", 
+                NONZERO_ERRORCODE, inner);
+        Assert.assertEquals(inner.getMessage(),
+                LogUtils.getPigException(outer).getMessage());
+    }
+}