You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by ol...@apache.org on 2009/01/24 00:07:32 UTC

svn commit: r737239 [1/6] - in /hadoop/pig/trunk: ./ src/org/apache/pig/ src/org/apache/pig/backend/ src/org/apache/pig/backend/datastorage/ src/org/apache/pig/backend/executionengine/ src/org/apache/pig/backend/executionengine/util/ src/org/apache/pig...

Author: olga
Date: Fri Jan 23 23:07:30 2009
New Revision: 737239

URL: http://svn.apache.org/viewvc?rev=737239&view=rev
Log:
PIG-589: error handling, phase 1-2 (sms via olgan)

Added:
    hadoop/pig/trunk/src/org/apache/pig/PigException.java
    hadoop/pig/trunk/src/org/apache/pig/backend/BackendException.java
    hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/MRCompilerException.java
    hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/LogicalToPhysicalTranslatorException.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/validators/TypeCheckerException.java
Modified:
    hadoop/pig/trunk/CHANGES.txt
    hadoop/pig/trunk/src/org/apache/pig/Main.java
    hadoop/pig/trunk/src/org/apache/pig/PigServer.java
    hadoop/pig/trunk/src/org/apache/pig/StandAloneParser.java
    hadoop/pig/trunk/src/org/apache/pig/backend/datastorage/DataStorageException.java
    hadoop/pig/trunk/src/org/apache/pig/backend/executionengine/ExecException.java
    hadoop/pig/trunk/src/org/apache/pig/backend/executionengine/util/ExecTools.java
    hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/HDataType.java
    hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/datastorage/HDataStorage.java
    hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/HExecutionEngine.java
    hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/CombinerOptimizer.java
    hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/JobControlCompiler.java
    hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/JobCreationException.java
    hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/MRCompiler.java
    hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/MapReduceLauncher.java
    hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/LogToPhyTranslationVisitor.java
    hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java
    hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/relationalOperators/POLocalRearrange.java
    hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/streaming/HadoopExecutableManager.java
    hadoop/pig/trunk/src/org/apache/pig/data/DataType.java
    hadoop/pig/trunk/src/org/apache/pig/data/DefaultTuple.java
    hadoop/pig/trunk/src/org/apache/pig/impl/PigContext.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/ExpressionOperator.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/FrontendException.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOBinCond.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOCogroup.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOConst.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOCross.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/LODistinct.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOFilter.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOForEach.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOGenerate.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOLoad.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOPrinter.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOProject.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOSort.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOSplit.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOSplitOutput.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOUnion.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOUserFunc.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/LogicalOperator.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/ProjectStarTranslator.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/optimizer/ImplicitSplitInserter.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/optimizer/OpLimitOptimizer.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/optimizer/StreamOptimizer.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/optimizer/TypeCastInserter.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/schema/Schema.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/schema/SchemaMergeException.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/validators/InputOutputFileVisitor.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/validators/LogicalPlanValidationExecutor.java
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/validators/TypeCheckingVisitor.java
    hadoop/pig/trunk/src/org/apache/pig/impl/plan/PlanException.java
    hadoop/pig/trunk/src/org/apache/pig/impl/plan/PlanValidationException.java
    hadoop/pig/trunk/src/org/apache/pig/impl/plan/VisitorException.java
    hadoop/pig/trunk/src/org/apache/pig/impl/plan/optimizer/OptimizerException.java
    hadoop/pig/trunk/src/org/apache/pig/impl/streaming/FileInputHandler.java
    hadoop/pig/trunk/src/org/apache/pig/tools/grunt/Grunt.java
    hadoop/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java
    hadoop/pig/trunk/src/org/apache/pig/tools/grunt/Utils.java
    hadoop/pig/trunk/test/org/apache/pig/test/TestBestFitCast.java
    hadoop/pig/trunk/test/org/apache/pig/test/TestDataModel.java
    hadoop/pig/trunk/test/org/apache/pig/test/TestGrunt.java
    hadoop/pig/trunk/test/org/apache/pig/test/TestInputOutputFileValidator.java
    hadoop/pig/trunk/test/org/apache/pig/test/TestJobSubmission.java
    hadoop/pig/trunk/test/org/apache/pig/test/TestLogToPhyCompiler.java
    hadoop/pig/trunk/test/org/apache/pig/test/TestLogicalOptimizer.java
    hadoop/pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java
    hadoop/pig/trunk/test/org/apache/pig/test/TestMRCompiler.java
    hadoop/pig/trunk/test/org/apache/pig/test/TestSchemaParser.java
    hadoop/pig/trunk/test/org/apache/pig/test/TypeGraphPrinter.java
    hadoop/pig/trunk/test/org/apache/pig/test/Util.java
    hadoop/pig/trunk/test/org/apache/pig/test/utils/dotGraph/LogicalPlanLoader.java
    hadoop/pig/trunk/test/org/apache/pig/test/utils/planComparer/LogicalPlanComparer.java

Modified: hadoop/pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=737239&r1=737238&r2=737239&view=diff
==============================================================================
--- hadoop/pig/trunk/CHANGES.txt (original)
+++ hadoop/pig/trunk/CHANGES.txt Fri Jan 23 23:07:30 2009
@@ -372,3 +372,5 @@
     PIG-622: Include pig executable in distribution (tomwhite via sms)
 
     PIG-628: misc performance improvements (pradeepk via olgan)
+    
+    PIG-589: error handling, phase 1-2 (sms via olgan):wq

Modified: hadoop/pig/trunk/src/org/apache/pig/Main.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/Main.java?rev=737239&r1=737238&r2=737239&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/Main.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/Main.java Fri Jan 23 23:07:30 2009
@@ -18,7 +18,6 @@
 package org.apache.pig;
 
 import java.io.*;
-import java.lang.reflect.Method;
 import java.util.*;
 import java.util.jar.*;
 import java.text.ParseException;
@@ -30,14 +29,9 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import org.apache.log4j.BasicConfigurator;
-import org.apache.log4j.Logger;
 import org.apache.log4j.Level;
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.PatternLayout;
 import org.apache.log4j.PropertyConfigurator;
 import org.apache.pig.ExecType;
-import org.apache.pig.backend.hadoop.executionengine.HExecutionEngine;
 import org.apache.pig.impl.PigContext;
 import org.apache.pig.impl.io.FileLocalizer;
 import org.apache.pig.impl.logicalLayer.LogicalPlanBuilder;
@@ -101,6 +95,7 @@
         opts.registerOpt('p', "param", CmdLineParser.ValueExpected.OPTIONAL);
         opts.registerOpt('m', "param_file", CmdLineParser.ValueExpected.OPTIONAL);
         opts.registerOpt('r', "dryrun", CmdLineParser.ValueExpected.NOT_ACCEPTED);
+        opts.registerOpt('l', "logfile", CmdLineParser.ValueExpected.REQUIRED);
 
         ExecMode mode = ExecMode.UNKNOWN;
         String file = null;
@@ -114,6 +109,8 @@
         if(clusterConfigured != null && clusterConfigured.length() > 0){
             cluster = clusterConfigured;
         }
+        
+        String logFileName = validateLogFile(null, null);       
 
         char opt;
         while ((opt = opts.getNextOpt()) != CmdLineParser.EndOfOpts) {
@@ -166,6 +163,18 @@
                 }
                 break;
 
+            case 'l':
+                //call to method that validates the path to the log file 
+                //and sets up the file to store the client side log file                
+                String logFileParameter = opts.getValStr();
+                if (logFileParameter != null && logFileParameter.length() > 0) {
+                    logFileName = validateLogFile(logFileParameter, null);
+                } else {
+                    logFileName = validateLogFile(logFileName, null);
+                }
+                properties.setProperty("pig.logfile", logFileName);
+                break;
+
             case 'm':
                 paramFiles.add(opts.getValStr());
                 break;
@@ -186,7 +195,7 @@
                 break;
                             
             case 'r': 
-                // currently only used for parameter substitition
+                // currently only used for parameter substitution
                 // will be extended in the future
                 dryrun = true;
                 break;
@@ -215,10 +224,11 @@
         configureLog4J(properties);
         // create the context with the parameter
         PigContext pigContext = new PigContext(execType, properties);
+        pigContext.getProperties().setProperty("pig.logfile", logFileName);
 
         LogicalPlanBuilder.classloader = pigContext.createCl(null);
 
-        // construct the parameter subsitution preprocessor
+        // construct the parameter substitution preprocessor
         Grunt grunt = null;
         BufferedReader in;
         String substFile = null;
@@ -227,7 +237,7 @@
             // Run, using the provided file as a pig file
             in = new BufferedReader(new FileReader(file));
 
-            // run parameter substition preoprocessor first
+            // run parameter substitution preprocessor first
             substFile = file + ".substituted";
             pin = runParamPreprocessor(in, params, paramFiles, substFile, debug || dryrun);
             if (dryrun){
@@ -235,11 +245,15 @@
                 return;
             }
 
+            logFileName = validateLogFile(logFileName, file);
+            pigContext.getProperties().setProperty("pig.logfile", logFileName);
+            
             if (!debug)
                 new File(substFile).deleteOnExit();
             
             grunt = new Grunt(pin, pigContext);
             grunt.exec();
+            rc = 0;
             return;
 
         case STRING: {
@@ -291,13 +305,16 @@
             mode = ExecMode.FILE;
             in = new BufferedReader(new FileReader(remainders[0]));
 
-            // run parameter substition preoprocessor first
+            // run parameter substitution preprocessor first
             substFile = remainders[0] + ".substituted";
             pin = runParamPreprocessor(in, params, paramFiles, substFile, debug || dryrun);
             if (dryrun){
                 log.info("Dry run completed. Substituted pig script is at " + substFile);
                 return;
             }
+            
+            logFileName = validateLogFile(logFileName, remainders[0]);
+            pigContext.getProperties().setProperty("pig.logfile", logFileName);
 
             if (!debug)
                 new File(substFile).deleteOnExit();
@@ -311,14 +328,18 @@
         // Per Utkarsh and Chris invocation of jar file via pig depricated.
     } catch (ParseException e) {
         usage();
-        rc = 1;
+        rc = 2;
     } catch (NumberFormatException e) {
         usage();
-        rc = 1;
+        rc = 2;
+    } catch (PigException pe) {
+        if(pe.retriable()) {
+            rc = 1; 
+        } else {
+            rc = 2;
+        }
     } catch (Throwable e) {
-        //log.error(e);
-        // this is a hack to see full error till we resolve commons logging config
-        e.printStackTrace();
+        rc = 2;
     } finally {
         // clear temp files
         FileLocalizer.deleteTempFiles();
@@ -336,7 +357,6 @@
     String log4jconf = properties.getProperty(LOG4J_CONF);
     String trueString = "true";
     boolean brief = trueString.equalsIgnoreCase(properties.getProperty(BRIEF));
-    boolean verbose = trueString.equalsIgnoreCase(properties.getProperty(VERBOSE));
     Level logLevel = Level.INFO;
 
     String logLevelString = properties.getProperty(DEBUG);
@@ -356,9 +376,9 @@
                            "org.apache.log4j.PatternLayout");
          props.setProperty("log4j.appender.PIGCONSOLE.layout.ConversionPattern",
                            "%d [%t] %-5p %c - %m%n");
+         props.setProperty("log4j.appender.PIGCONSOLE.target",
+         "System.err");
          PropertyConfigurator.configure(props);
-         // Set the log level/threshold
-         Logger.getRootLogger().setLevel(verbose ? Level.ALL : logLevel);
      } else {
          // brief logging - no timestamps
          Properties props = new Properties();
@@ -369,13 +389,13 @@
                            "org.apache.log4j.PatternLayout");
          props.setProperty("log4j.appender.PIGCONSOLE.layout.ConversionPattern",
                            "%m%n");
+         props.setProperty("log4j.appender.PIGCONSOLE.target",
+         "System.err");
          PropertyConfigurator.configure(props);
-         // Set the log level/threshold
-         Logger.getRootLogger().setLevel(verbose ? Level.ALL : logLevel);
      }
 }
  
-// retruns the stream of final pig script to be passed to Grunt
+// returns the stream of final pig script to be passed to Grunt
 private static BufferedReader runParamPreprocessor(BufferedReader origPigScript, ArrayList<String> params,
                                             ArrayList<String> paramFiles, String scriptFile, boolean createFile) 
                                 throws org.apache.pig.tools.parameters.ParseException, IOException{
@@ -431,8 +451,97 @@
     System.out.println("    -h, -help display this message");
     System.out.println("    -j, -jar jarfile load jarfile"); 
     System.out.println("    -o, -hod read hod server from system property ssh.gateway");
-    System.out.println("    -v, -verbose print all log messages to screen (default to print only INFO and above to screen)");
+    System.out.println("    -v, -verbose print all error messages to screen");
     System.out.println("    -x, -exectype local|mapreduce, mapreduce is default");
     System.out.println("    -i, -version display version information");
+    System.out.println("    -l, -logfile path to client side log file; current working directory is default");
 }
+
+private static String validateLogFile(String logFileName, String scriptName) {
+    String strippedDownScriptName = null;
+    
+    if(scriptName != null) {
+        File scriptFile = new File(scriptName);
+        if(!scriptFile.isDirectory()) {
+            String scriptFileAbsPath;
+            try {
+                scriptFileAbsPath = scriptFile.getCanonicalPath();
+            } catch (IOException ioe) {
+                throw new AssertionError("Could not compute canonical path to the script file " + ioe.getMessage());      
+            }            
+            strippedDownScriptName = getFileFromCanonicalPath(scriptFileAbsPath);
+        }
+    }
+    
+    String defaultLogFileName = (strippedDownScriptName == null ? "pig_" : strippedDownScriptName) + new Date().getTime() + ".log";
+    File logFile;    
+    
+    if(logFileName != null) {
+        logFile = new File(logFileName);
+    
+        //Check if the file name is a directory 
+        //append the default file name to the file
+        if(logFile.isDirectory()) {            
+            if(logFile.canWrite()) {
+                try {
+                    logFileName += logFile.getCanonicalPath() + File.separator + defaultLogFileName;
+                } catch (IOException ioe) {
+                    throw new AssertionError("Could not compute canonical path to the log file " + ioe.getMessage());       
+                }
+                return logFileName;
+            } else {
+                throw new AssertionError("Need write permission in the directory: " + logFileName + " to create log file.");
+            }
+        } else {
+            //we have a relative path or an absolute path to the log file
+            //check if we can write to the directory where this file is/will be stored
+            
+            if (logFile.exists()) {
+                if(logFile.canWrite()) {
+                    try {
+                        logFileName = new File(logFileName).getCanonicalPath();
+                    } catch (IOException ioe) {
+                        throw new AssertionError("Could not compute canonical path to the log file " + ioe.getMessage());
+                    }
+                    return logFileName;
+                } else {
+                    //do not have write permissions for the log file
+                    //bail out with an error message
+                    throw new AssertionError("Cannot write to file: " + logFileName + ". Need write permission.");
+                }
+            } else {
+                logFile = logFile.getParentFile();
+                
+                if(logFile != null) {
+                    //if the directory is writable we are good to go
+                    if(logFile.canWrite()) {
+                        try {
+                            logFileName = new File(logFileName).getCanonicalPath();
+                        } catch (IOException ioe) {
+                            throw new AssertionError("Could not compute canonical path to the log file " + ioe.getMessage());
+                        }
+                        return logFileName;
+                    } else {
+                        throw new AssertionError("Need write permission in the directory: " + logFile + " to create log file.");
+                    }
+                }//end if logFile != null else is the default in fall through                
+            }//end else part of logFile.exists()
+        }//end else part of logFile.isDirectory()
+    }//end if logFileName != null
+    
+    //file name is null or its in the current working directory 
+    //revert to the current working directory
+    String currDir = System.getProperty("user.dir");
+    logFile = new File(currDir);
+    if(logFile.canWrite()) {
+        logFileName = currDir + File.separator + (logFileName == null? defaultLogFileName : logFileName);
+        return logFileName;
+    }    
+    throw new RuntimeException("Cannot write to log file: " + logFileName);
+}
+
+private static String getFileFromCanonicalPath(String canonicalPath) {
+    return canonicalPath.substring(canonicalPath.lastIndexOf(File.separator));
+}
+
 }

Added: hadoop/pig/trunk/src/org/apache/pig/PigException.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/PigException.java?rev=737239&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/PigException.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/PigException.java Fri Jan 23 23:07:30 2009
@@ -0,0 +1,297 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+/**
+ * All exceptions in Pig are encapsulated in the <code>PigException</code>
+ * class. Details such as the source of the error, error message, error
+ * code, etc. are contained in this class. The default values for the
+ * attributes are:
+ * errorSource = BUG
+ * errorCode = 0
+ * retriable = false
+ * detailedMessage = null
+ */
+public class PigException extends IOException {
+
+    /*
+     * Instead of using an enum for the source of the error,
+     * the classic style of using static final is adopted
+     */
+    public static final byte INPUT = 2;
+    public static final byte BUG = 4;
+    public static final byte USER_ENVIRONMENT = 8;
+    public static final byte REMOTE_ENVIRONMENT = 16;
+
+    /**
+     * A static method to query if an error source is due to
+     * an input or not.
+     *
+     * @param errSource - byte that indicates the error source
+     * @return true if the error source is an input; false otherwise
+     */
+    public static boolean isInput(byte errSource) {
+        return ((errSource & INPUT) == 0 ? false : true);
+    }
+
+    /**
+     * A static method to query if an error source is due to
+     * a bug or not.
+     *
+     * @param errSource - byte that indicates the error source
+     * @return true if the error source is a bug; false otherwise
+     */
+    public static boolean isBug(byte errSource) {
+        return ((errSource & BUG) == 0 ? false : true);
+    }
+
+    /**
+     * A static method to query if an error source is due to
+     * the user environment or not.
+     *
+     * @param errSource - byte that indicates the error source
+     * @return true if the error source is due to the user environment; false otherwise
+     */
+    public static boolean isUserEnvironment(byte errSource) {
+        return ((errSource & USER_ENVIRONMENT) == 0 ? false : true);
+    }
+
+    /**
+     * A static method to query if an error source is due to
+     * the remote environment or not.
+     *
+     * @param errSource - byte that indicates the error source
+     * @return true if the error source is due to the remote environment; false otherwise
+     */
+    public static boolean isRemoteEnvironment(byte errSource) {
+        return ((errSource & REMOTE_ENVIRONMENT) == 0 ? false : true);
+    }
+    
+    protected int errorCode = 0;
+    protected byte errorSource = BUG;
+    protected boolean retriable = false;
+    protected String detailedMessage = null;
+
+    /**
+     * Create a new PigException with null as the error message.
+     */
+    public PigException() {
+        super();
+    }
+    
+    /**
+     * Create a new PigException with the specified message.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     */
+    public PigException(String message) {
+        super(message);
+    }
+    
+    /**
+     * Create a new PigException with the specified cause.
+     *
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
+     */
+    public PigException(Throwable cause) {
+        super(cause);
+    }
+
+    /**
+     * Create a new PigException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
+     */
+    public PigException (String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * Create a new PigException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     */
+    public PigException (String message, int errCode) {
+        this(message);
+        errorCode = errCode;
+    }
+
+    /**
+     * Create a new PigException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown. 
+     */
+    public PigException (String message, int errCode, Throwable cause) {
+        this(message, cause);
+        errorCode = errCode;
+    }
+
+    /**
+     * Create a new PigException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source 
+     */
+    public PigException (String message, int errCode, byte errSrc) {
+        this(message, errCode, errSrc, false, null);
+    }
+
+    /**
+     * Create a new PigException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown. 
+     */
+    public PigException (String message, int errCode, byte errSrc, Throwable cause) {
+        this(message, errCode, errSrc, false, null, cause);
+    }
+
+    /**
+     * Create a new PigException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param retry - If the exception is retriable or not
+     */
+    public PigException (String message, int errCode, boolean retry) {
+        this(message);
+        errorCode = errCode;
+        retriable = retry;
+    }
+
+    /**
+     * Create a new PigException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source 
+     * @param retry - If the exception is retriable or not
+     */
+    public PigException (String message, int errCode, byte errSrc, boolean retry) {
+        this(message, errCode, errSrc, retry, null);
+    }
+
+    /**
+     * Create a new PigException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source 
+     * @param retry - If the exception is retriable or not
+     * @param detailedMsg - The detailed message shown to the developer 
+     */
+    public PigException (String message, int errCode, byte errSrc, boolean retry, String detailedMsg) {
+        super(message);
+        errorCode = errCode;
+        errorSource = errSrc;
+        retriable = retry;
+        detailedMessage = detailedMsg;
+    }
+
+    /**
+     * Create a new PigException with the specified message, error code, error source, retriable or not, detalied message for the developer and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source 
+     * @param retry - If the exception is retriable or not
+     * @param detailedMsg - The detailed message shown to the developer 
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
+     */
+    public PigException (String message, int errCode, byte errSrc, boolean retry, String detailedMsg, Throwable cause) {
+        super(message, cause);
+        errorCode = errCode;
+        errorSource = errSrc;
+        retriable = retry;
+        detailedMessage = detailedMsg;
+    }    
+    
+    /**
+     * Checks if the exception is retriable.
+     * @return if the exception is retriable or not
+     */
+    public boolean retriable() {
+        return retriable;
+    }
+
+    /**
+     * Set the retriable attribute of the exception
+     * @param retry - true if retriable; false otherwise
+     */
+    public void setRetriable(boolean retry) {
+        retriable = retry;
+    }
+
+    /**
+     * Returns the error source of the exception. Can be more than one source.
+     * @return error sources represented as a byte
+     */
+    public byte getErrorSource() {
+        return errorSource;
+    }
+
+    /**
+     * Set the error source of the exception
+     * @param src - byte representing the error sources
+     */
+    public void setErrorSource(byte src) {
+        errorSource = src;
+    }
+
+    /**
+     * Returns the error code of the exception
+     * @return error code of the exception
+     */
+    public int getErrorCode() {
+        return errorCode;
+    }
+
+    /**
+     * Set the error code of the exception
+     * @param code - error code
+     */
+    public void setErrorCode(int code) {
+        errorCode = code;
+    }
+
+    /**
+     * Returns the detailed message used by developers for debugging
+     * @return detailed message
+     */
+    public String getDetailedMessage() {
+        return detailedMessage;
+    }
+
+    /**
+     * Set the detailed message of the exception
+     * @param msg - detailed message to be used by developers
+     */
+    public void setDetailedMessage(String detailMsg) {
+        detailedMessage = detailMsg;
+    }
+
+}

Modified: hadoop/pig/trunk/src/org/apache/pig/PigServer.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/PigServer.java?rev=737239&r1=737238&r2=737239&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/PigServer.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/PigServer.java Fri Jan 23 23:07:30 2009
@@ -60,17 +60,16 @@
 import org.apache.pig.impl.logicalLayer.validators.LogicalPlanValidationExecutor;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhysicalPlan;
 import org.apache.pig.impl.plan.CompilationMessageCollector;
-import org.apache.pig.impl.plan.DependencyOrderWalker;
 import org.apache.pig.impl.plan.OperatorKey;
-import org.apache.pig.impl.plan.OperatorPlan;
 import org.apache.pig.impl.streaming.StreamingCommand;
-import org.apache.pig.impl.util.WrappedIOException;
 import org.apache.pig.impl.util.PropertiesUtil;
 import org.apache.pig.impl.logicalLayer.LODefine;
 import org.apache.pig.impl.logicalLayer.LOStore;
 import org.apache.pig.pen.ExampleGenerator;
+import org.apache.pig.tools.grunt.Utils;
 import org.apache.pig.tools.grunt.GruntParser;
 
+
 /**
  * 
  * This class is the program's connection to Pig. Typically a program will create a PigServer
@@ -91,7 +90,9 @@
         if (normStr.equals("pig")) return ExecType.PIG;
         if (normStr.equals("pigbody")) return ExecType.PIG;
    
-        throw new IOException("Unrecognized exec type: " + str);
+        int errCode = 2040;
+        String msg = "Unknown exec type: " + str;
+        throw new PigException(msg, errCode, PigException.BUG);
     }
 
 
@@ -241,7 +242,9 @@
                 File f = new File(name);
                 
                 if (!f.canRead()) {
-                    throw new IOException("Can't read jar file: " + name);
+                    int errCode = 4002;
+                    String msg = "Can't read jar file: " + name;
+                    throw new FrontendException(msg, errCode, PigException.USER_ENVIRONMENT);
                 }
                 
                 resource = f.toURI().toURL();
@@ -280,7 +283,9 @@
                 try{
                     execute(null);
                 } catch (Exception e) {
-                    throw WrappedIOException.wrap("Unable to store for alias: " + op.getOperatorKey().getId(), e);
+                    int errCode = 1002;
+                    String msg = "Unable to store alias " + op.getOperatorKey().getId();
+                    throw new FrontendException(msg, errCode, PigException.INPUT, e);
                 }
             }
         }
@@ -298,7 +303,11 @@
             return new LogicalPlanBuilder(pigContext).parse(scope, query,
                     aliasesMap, opTableMap, aliasOpMap, startLine);
         } catch (ParseException e) {
-            throw (IOException) new IOException(e.getMessage()).initCause(e);
+            //throw (IOException) new IOException(e.getMessage()).initCause(e);
+            PigException pe = Utils.getPigException(e);
+            int errCode = 1000;
+            String msg = "Error during parsing. " + (pe == null? e.getMessage() : pe.getMessage());
+            throw new FrontendException(msg, errCode, PigException.INPUT, false, null, e);
         }
     }
 
@@ -342,7 +351,9 @@
             // alias supplied
             LogicalOperator op = cloneAliasOp.get(alias);
             if(op == null) {
-                throw new IOException("Unable to find an operator for alias " + alias);
+                int errCode = 1003;
+                String msg = "Unable to find an operator for alias " + alias;
+                throw new FrontendException(msg, errCode, PigException.INPUT);
             }
             return cloneAliases.get(op);
         }
@@ -372,18 +383,15 @@
     public Schema dumpSchema(String alias) throws IOException{
         try {
             LogicalPlan lp = getPlanFromAlias(alias, "describe");
-            try {
-                lp = compileLp(alias, false);
-            } catch (ExecException e) {
-                throw new FrontendException(e.getMessage());
-            }
+            lp = compileLp(alias, false);
             Schema schema = lp.getLeaves().get(0).getSchema();
             if (schema != null) System.out.println(alias + ": " + schema.toString());    
             else System.out.println("Schema for " + alias + " unknown.");
             return schema;
-        } catch (FrontendException fe) {
-            throw WrappedIOException.wrap(
-                "Unable to describe schema for alias " + alias, fe);
+        } catch (FrontendException fee) {
+            int errCode = 1001;
+            String msg = "Unable to describe schema for alias " + alias; 
+            throw new FrontendException (msg, errCode, PigException.INPUT, false, null, fee);
         }
     }
 
@@ -399,7 +407,9 @@
         try {
             LogicalOperator op = aliasOp.get(id);
             if(null == op) {
-                throw new IOException("Unable to find an operator for alias " + id);
+                int errCode = 1003;
+                String msg = "Unable to find an operator for alias " + id;
+                throw new FrontendException(msg, errCode, PigException.INPUT);
             }
 //            ExecJob job = execute(getPlanFromAlias(id, op.getClass().getName()));
             ExecJob job = store(id, FileLocalizer.getTemporaryPath(null, pigContext).toString(), BinStorage.class.getName() + "()");
@@ -411,8 +421,9 @@
                     + job.getStatus().toString());
             }
         } catch (Exception e) {
-            throw WrappedIOException.wrap(
-                "Unable to open iterator for alias: " + id, e);
+            int errCode = 1066;
+            String msg = "Unable to open iterator for alias " + id; 
+            throw new FrontendException(msg, errCode, PigException.INPUT, e);
         }
     }
     
@@ -441,7 +452,9 @@
             LogicalPlan readFrom = getPlanFromAlias(id, "store");
             return store(id, readFrom, filename, func);
         } catch (FrontendException fe) {
-            throw WrappedIOException.wrap("Unable to store alias " + id, fe);
+            int errCode = 1002;
+            String msg = "Unable to store alias " + id;
+            throw new FrontendException(msg, errCode, PigException.INPUT, fe);
         }
     }
         
@@ -472,8 +485,9 @@
             LogicalPlan storePlan = QueryParser.generateStorePlan(scope, lp, filename, func, leaf);
             return executeCompiledLogicalPlan(storePlan);
         } catch (Exception e) {
-            throw WrappedIOException.wrap("Unable to store for alias: " +
-                id, e);
+            int errCode = 1002;
+            String msg = "Unable to store alias " + id;
+            throw new FrontendException(msg, errCode, PigException.INPUT, e);
         }
 
     }
@@ -521,8 +535,9 @@
             pigContext.getExecutionEngine().explain(pp, stream);
       
         } catch (Exception e) {
-            throw WrappedIOException.wrap("Unable to explain alias " +
-                alias, e);
+            int errCode = 1067;
+            String msg = "Unable to explain alias " + alias;
+            throw new FrontendException(msg, errCode, PigException.INPUT, e);
         }
     }
 
@@ -672,13 +687,13 @@
     }
 
     private LogicalPlan compileLp(
-            String alias) throws ExecException, FrontendException {
+            String alias) throws FrontendException {
         return compileLp(alias, true);
     }
 
     private LogicalPlan compileLp(
             String alias,
-            boolean optimize) throws ExecException, FrontendException {
+            boolean optimize) throws FrontendException {
         
         // create a clone of the logical plan and give it
         // to the operations below
@@ -686,7 +701,9 @@
         try {
              lpClone = clonePlan(alias);
         } catch (IOException e) {
-            throw new FrontendException("Unable to clone plan before compiling", e);
+            int errCode = 2001;
+            String msg = "Unable to clone plan before compiling";
+            throw new FrontendException(msg, errCode, PigException.BUG, e);
         }
 
         
@@ -707,7 +724,7 @@
             // Need to go through and see what the collector has in it.  But
             // remember what we've caught so we can wrap it into what we
             // throw.
-            caught = fe;
+            caught = fe;            
         }
         // Check to see if we had any problems.
         StringBuilder sb = new StringBuilder();
@@ -723,8 +740,7 @@
 
             case Unknown:
             case Error:
-                log.error(msg.getMessage());
-                sb.append(msg.getMessage());
+                //Error messages are displayed separately and are not bundled here
                 break;
 
             default:
@@ -735,7 +751,9 @@
         }
 
         if (sb.length() > 0 || caught != null) {
-            throw new ExecException(sb.toString(), caught);
+            //int errCode = 1003;
+            //throw new FrontendException(sb.toString(), errCode, PigException.INPUT, false, null, caught);
+            throw caught;
         }
 
         // optimize
@@ -761,13 +779,15 @@
             String operation) throws FrontendException {
         LogicalOperator lo = aliasOp.get(alias);
         if (lo == null) {
-            throw new FrontendException("No alias " + alias + " to " +
-                operation);
+            int errCode = 1004;
+            String msg = "No alias " + alias + " to " + operation;
+            throw new FrontendException(msg, errCode, PigException.INPUT, false, null);
         }
         LogicalPlan lp = aliases.get(lo);
         if (lp == null) {
-            throw new FrontendException("No plan for " + alias + " to " +
-                operation);
+            int errCode = 1005;
+            String msg = "No plan for " + alias + " to " + operation;
+            throw new FrontendException(msg, errCode, PigException.INPUT, false, null);
         }        
         return lp;
     }

Modified: hadoop/pig/trunk/src/org/apache/pig/StandAloneParser.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/StandAloneParser.java?rev=737239&r1=737238&r2=737239&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/StandAloneParser.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/StandAloneParser.java Fri Jan 23 23:07:30 2009
@@ -79,8 +79,6 @@
             }
         } catch (IOException e) {
             log.error(e);
-        } catch (FrontendException fe) {
-            log.error(fe);
         }
     }
 }

Added: hadoop/pig/trunk/src/org/apache/pig/backend/BackendException.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/backend/BackendException.java?rev=737239&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/backend/BackendException.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/backend/BackendException.java Fri Jan 23 23:07:30 2009
@@ -0,0 +1,157 @@
+/*
+ * 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.backend;
+
+import org.apache.pig.PigException;
+
+public class BackendException extends PigException {
+
+    /**
+     * Create a new BackendException with null as the error message.
+     */
+    public BackendException() {
+        super();
+    }
+    
+    /**
+     * Create a new BackendException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     */
+    public BackendException(String message) {
+        super(message);
+    }
+    
+    /**
+     * Create a new BackendException with the specified cause.
+     *
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
+     */
+    public BackendException(Throwable cause) {
+        super(cause);
+    }
+
+    /**
+     * Create a new BackendException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
+     */
+    public BackendException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * Create a new BackendException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     */
+    public BackendException(String message, int errCode) {
+        super(message, errCode);
+    }
+
+    /**
+     * Create a new BackendException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown. 
+     */
+    public BackendException(String message, int errCode, Throwable cause) {
+        super(message, errCode, cause);
+    }
+
+    /**
+     * Create a new BackendException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source 
+     */
+    public BackendException(String message, int errCode, byte errSrc) {
+        super(message, errCode, errSrc);
+    }   
+
+    /**
+     * Create a new BackendException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown. 
+     */
+    public BackendException(String message, int errCode, byte errSrc,
+            Throwable cause) {
+        super(message, errCode, errSrc, cause);
+    }
+
+    /**
+     * Create a new BackendException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param retry - If the exception is retriable or not
+     */ 
+    public BackendException(String message, int errCode, boolean retry) {
+        super(message, errCode, retry);
+    }
+
+    /**
+     * Create a new BackendException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source 
+     * @param retry - If the exception is retriable or not
+     */
+    public BackendException(String message, int errCode, byte errSrc,
+            boolean retry) {
+        super(message, errCode, errSrc, retry);
+    }    
+
+	/**
+     * Create a new BackendException with the specified message, error code, error source, retriable or not, detalied message for the developer and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source 
+     * @param retry - If the exception is retriable or not
+     * @param detailedMsg - The detailed message shown to the developer 
+     */
+	public BackendException(String message, int errCode, byte errSrc,
+			boolean retry, String detailedMsg) {
+		super(message, errCode, errSrc, retry, detailedMsg);
+	}
+    
+    /**
+     * Create a new BackendException with the specified message, error code, error source, retriable or not, detalied message for the developer and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source 
+     * @param retry - If the exception is retriable or not
+     * @param detailedMsg - The detailed message shown to the developer 
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
+     */
+    public BackendException(String message, int errCode, byte errSrc,
+            boolean retry, String detailedMsg, Throwable cause) {
+        super(message, errCode, errSrc, retry, detailedMsg, cause);
+    }
+
+}
\ No newline at end of file

Modified: hadoop/pig/trunk/src/org/apache/pig/backend/datastorage/DataStorageException.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/backend/datastorage/DataStorageException.java?rev=737239&r1=737238&r2=737239&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/backend/datastorage/DataStorageException.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/backend/datastorage/DataStorageException.java Fri Jan 23 23:07:30 2009
@@ -18,26 +18,142 @@
 
 package org.apache.pig.backend.datastorage;
 
-import java.io.IOException;
+import org.apache.pig.backend.BackendException;
 
-public class DataStorageException extends IOException {
+public class DataStorageException extends BackendException {
 
     static final long serialVersionUID = 1;
     
-    public DataStorageException(String message, Throwable cause) {
-        super(message);
-        initCause(cause);
-    }
-
+    /**
+     * Create a new DataStorageException with null as the error message.
+     */
     public DataStorageException() {
-        this(null, null);
+        super();
     }
     
+    /**
+     * Create a new DataStorageException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     */
     public DataStorageException(String message) {
-        this(message, null);
+        super(message);
     }
     
+    /**
+     * Create a new DataStorageException with the specified cause.
+     *
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
+     */
     public DataStorageException(Throwable cause) {
-        this(null, cause);
+        super(cause);
+    }
+
+    /**
+     * Create a new DataStorageException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
+     */
+    public DataStorageException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * Create a new DataStorageException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     */
+    public DataStorageException(String message, int errCode) {
+        super(message, errCode);
+    }
+
+    /**
+     * Create a new DataStorageException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown. 
+     */
+    public DataStorageException(String message, int errCode, Throwable cause) {
+        super(message, errCode, cause);
+    }
+
+    /**
+     * Create a new DataStorageException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source 
+     */
+    public DataStorageException(String message, int errCode, byte errSrc) {
+        super(message, errCode, errSrc);
+    }   
+
+    /**
+     * Create a new DataStorageException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown. 
+     */
+    public DataStorageException(String message, int errCode, byte errSrc,
+            Throwable cause) {
+        super(message, errCode, errSrc, cause);
+    }
+
+    /**
+     * Create a new DataStorageException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param retry - If the exception is retriable or not
+     */ 
+    public DataStorageException(String message, int errCode, boolean retry) {
+        super(message, errCode, retry);
+    }
+
+    /**
+     * Create a new DataStorageException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source 
+     * @param retry - If the exception is retriable or not
+     */
+    public DataStorageException(String message, int errCode, byte errSrc,
+            boolean retry) {
+        super(message, errCode, errSrc, retry);
+    }    
+
+    /**
+     * Create a new DataStorageException with the specified message, error code, error source, retriable or not, detalied message for the developer and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source 
+     * @param retry - If the exception is retriable or not
+     * @param detailedMsg - The detailed message shown to the developer 
+     */
+    public DataStorageException(String message, int errCode, byte errSrc,
+            boolean retry, String detailedMsg) {
+        super(message, errCode, errSrc, retry, detailedMsg);
+    }
+    
+    /**
+     * Create a new DataStorageException with the specified message, error code, error source, retriable or not, detalied message for the developer and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source 
+     * @param retry - If the exception is retriable or not
+     * @param detailedMsg - The detailed message shown to the developer 
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
+     */
+    public DataStorageException(String message, int errCode, byte errSrc,
+            boolean retry, String detailedMsg, Throwable cause) {
+        super(message, errCode, errSrc, retry, detailedMsg, cause);
     }
 }

Modified: hadoop/pig/trunk/src/org/apache/pig/backend/executionengine/ExecException.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/backend/executionengine/ExecException.java?rev=737239&r1=737238&r2=737239&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/backend/executionengine/ExecException.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/backend/executionengine/ExecException.java Fri Jan 23 23:07:30 2009
@@ -18,22 +18,141 @@
 
 package org.apache.pig.backend.executionengine;
 
-public class ExecException extends Exception {
+import org.apache.pig.backend.BackendException;
+
+public class ExecException extends BackendException {
     static final long serialVersionUID = 1;
     
-    public ExecException (String message, Throwable cause) {
-        super(message, cause);
-    }
-
+    /**
+     * Create a new ExecException with null as the error message.
+     */
     public ExecException() {
         super();
     }
     
+    /**
+     * Create a new ExecException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     */
     public ExecException(String message) {
         super(message);
     }
     
+    /**
+     * Create a new ExecException with the specified cause.
+     *
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
+     */
     public ExecException(Throwable cause) {
         super(cause);
     }
+
+    /**
+     * Create a new ExecException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
+     */
+    public ExecException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * Create a new ExecException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     */
+    public ExecException(String message, int errCode) {
+        super(message, errCode);
+    }
+
+    /**
+     * Create a new ExecException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown. 
+     */
+    public ExecException(String message, int errCode, Throwable cause) {
+        super(message, errCode, cause);
+    }
+
+    /**
+     * Create a new ExecException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source 
+     */
+    public ExecException(String message, int errCode, byte errSrc) {
+        super(message, errCode, errSrc);
+    }   
+
+    /**
+     * Create a new ExecException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown. 
+     */
+    public ExecException(String message, int errCode, byte errSrc,
+            Throwable cause) {
+        super(message, errCode, errSrc, cause);
+    }
+
+    /**
+     * Create a new ExecException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param retry - If the exception is retriable or not
+     */ 
+    public ExecException(String message, int errCode, boolean retry) {
+        super(message, errCode, retry);
+    }
+
+    /**
+     * Create a new ExecException with the specified message and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source 
+     * @param retry - If the exception is retriable or not
+     */
+    public ExecException(String message, int errCode, byte errSrc,
+            boolean retry) {
+        super(message, errCode, errSrc, retry);
+    }    
+
+    /**
+     * Create a new ExecException with the specified message, error code, error source, retriable or not, detalied message for the developer and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source 
+     * @param retry - If the exception is retriable or not
+     * @param detailedMsg - The detailed message shown to the developer 
+     */
+    public ExecException(String message, int errCode, byte errSrc,
+            boolean retry, String detailedMsg) {
+        super(message, errCode, errSrc, retry, detailedMsg);
+    }
+    
+    /**
+     * Create a new ExecException with the specified message, error code, error source, retriable or not, detalied message for the developer and cause.
+     *
+     * @param message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user 
+     * @param errCode - The error code shown to the user 
+     * @param errSrc - The error source 
+     * @param retry - If the exception is retriable or not
+     * @param detailedMsg - The detailed message shown to the developer 
+     * @param cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
+     */
+    public ExecException(String message, int errCode, byte errSrc,
+            boolean retry, String detailedMsg, Throwable cause) {
+        super(message, errCode, errSrc, retry, detailedMsg, cause);
+    }
 }

Modified: hadoop/pig/trunk/src/org/apache/pig/backend/executionengine/util/ExecTools.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/backend/executionengine/util/ExecTools.java?rev=737239&r1=737238&r2=737239&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/backend/executionengine/util/ExecTools.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/backend/executionengine/util/ExecTools.java Fri Jan 23 23:07:30 2009
@@ -19,6 +19,7 @@
 package org.apache.pig.backend.executionengine.util;
 
 import org.apache.pig.FuncSpec;
+import org.apache.pig.PigException;
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhysicalPlan;
@@ -57,7 +58,9 @@
             }
             return spec;
         } catch (Exception e) {
-            throw new ExecException(e);
+            int errCode = 2045;
+            String msg = "Internal error. Not able to check if the leaf node is a store operator.";
+            throw new ExecException(msg, errCode, PigException.BUG, e);
         }
     }
 

Modified: hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/HDataType.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/HDataType.java?rev=737239&r1=737238&r2=737239&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/HDataType.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/HDataType.java Fri Jan 23 23:07:30 2009
@@ -27,6 +27,7 @@
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.WritableComparable;
 
+import org.apache.pig.PigException;
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.backend.hadoop.DoubleWritable;
 import org.apache.pig.data.BagFactory;
@@ -140,9 +141,12 @@
             break;
         default:
             if (typeToName == null) typeToName = DataType.genTypeToNameMap();
-            throw new ExecException("The type "
-                    + typeToName.get(type)
-                    + " cannot be collected as a Key type");
+            int errCode = 2044;
+            String msg = "The type "
+                + typeToName.get(type)
+                + " cannot be collected as a Key type";
+            throw new ExecException(msg, errCode, PigException.BUG);
+
         }
         // should never come here
         return null;
@@ -182,9 +186,11 @@
             throw new RuntimeException("Map not supported as a key type!");
         default:
             if (typeToName == null) typeToName = DataType.genTypeToNameMap();
-            throw new ExecException("The type "
-                    + typeToName.get(type)
-                    + " cannot be collected as a Key type");
+            int errCode = 2044;
+            String msg = "The type "
+                + typeToName.get(type)
+                + " cannot be collected as a Key type";
+            throw new ExecException(msg, errCode, PigException.BUG);
         }
         return wcKey;
     }

Modified: hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/datastorage/HDataStorage.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/datastorage/HDataStorage.java?rev=737239&r1=737238&r2=737239&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/datastorage/HDataStorage.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/datastorage/HDataStorage.java Fri Jan 23 23:07:30 2009
@@ -32,6 +32,7 @@
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.dfs.DistributedFileSystem;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.pig.PigException;
 import org.apache.pig.backend.datastorage.ContainerDescriptor;
 import org.apache.pig.backend.datastorage.DataStorage;
 import org.apache.pig.backend.datastorage.DataStorageException;
@@ -204,7 +205,9 @@
             }
         }
         catch (IOException e) {
-            throw new DataStorageException("Unable to check name " + name, e);
+            int errCode = 6007;
+            String msg = "Unable to check name " + name;
+            throw new DataStorageException(msg, errCode, PigException.REMOTE_ENVIRONMENT, e);
         }
         
         return isContainer;
@@ -228,8 +231,9 @@
 
             return hpaths.toArray(new HPath[hpaths.size()]);
         } catch (IOException e) {
-            throw new DataStorageException("Failed to obtain glob for "
-                    + pattern, e);
+            int errCode = 6008;
+            String msg = "Failed to obtain glob for " + pattern;
+            throw new DataStorageException(msg, errCode, PigException.REMOTE_ENVIRONMENT, e);
         }
     }
     

Modified: hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/HExecutionEngine.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/HExecutionEngine.java?rev=737239&r1=737238&r2=737239&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/HExecutionEngine.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/HExecutionEngine.java Fri Jan 23 23:07:30 2009
@@ -48,6 +48,7 @@
 import org.apache.hadoop.mapred.JobConf;
 import org.apache.hadoop.mapred.JobTracker;
 import org.apache.pig.FuncSpec;
+import org.apache.pig.PigException;
 import org.apache.pig.backend.datastorage.DataStorage;
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.backend.executionengine.ExecJob;
@@ -198,7 +199,9 @@
             jobClient = new JobClient(new JobConf(configuration));
         }
         catch (IOException e) {
-            throw new ExecException("Failed to create job client", e);
+            int errCode = 6009;
+            String msg = "Failed to create job client";
+            throw new ExecException(msg, errCode, PigException.BUG, e);
         }
     }
 
@@ -222,7 +225,9 @@
     public PhysicalPlan compile(LogicalPlan plan,
                                 Properties properties) throws ExecException {
         if (plan == null) {
-            throw new ExecException("No Plan to compile");
+            int errCode = 2041;
+            String msg = "No Plan to compile";
+            throw new ExecException(msg, errCode, PigException.BUG);
         }
 
         try {
@@ -232,7 +237,9 @@
             translator.visit();
             return translator.getPhysicalPlan();
         } catch (VisitorException ve) {
-            throw new ExecException(ve);
+            int errCode = 2042;
+            String msg = "Internal error. Unable to translate logical plan to physical plan.";
+            throw new ExecException(msg, errCode, PigException.BUG, ve);
         }
     }
 
@@ -252,7 +259,11 @@
             // There are a lot of exceptions thrown by the launcher.  If this
             // is an ExecException, just let it through.  Else wrap it.
             if (e instanceof ExecException) throw (ExecException)e;
-            else throw new ExecException(e.getMessage(), e);
+            else {
+                int errCode = 2043;
+                String msg = "Error during execution.";
+                throw new ExecException(msg, errCode, PigException.BUG, e);
+            }
         }
 
     }
@@ -383,13 +394,19 @@
         	}
 
             hdfs = properties.getProperty(FILE_SYSTEM_LOCATION);
-            if (hdfs == null)
-                throw new ExecException("Missing fs.default.name from hadoop configuration");
+            if (hdfs == null) {
+                int errCode = 4007;
+                String msg = "Missing fs.default.name from hadoop configuration.";
+                throw new ExecException(msg, errCode, PigException.USER_ENVIRONMENT);
+            }
             log.info("HDFS: " + hdfs);
 
             mapred = properties.getProperty(JOB_TRACKER_LOCATION);
-            if (mapred == null)
-                throw new ExecException("Missing mapred.job.tracker from hadoop configuration");
+            if (mapred == null) {
+                int errCode = 4007;
+                String msg = "Missing mapred.job.tracker from hadoop configuration";
+                throw new ExecException(msg, errCode, PigException.USER_ENVIRONMENT);
+            }
             log.info("JobTracker: " + mapred);
 
             // this is not longer needed as hadoop-site.xml given to us by HOD
@@ -402,9 +419,9 @@
             return new String[] {hdfs, mapred};
         } 
         catch (Exception e) {
-            ExecException ee = new ExecException("Could not connect to HOD");
-            ee.initCause(e);
-            throw ee;
+            int errCode = 6010;
+            String msg = "Could not connect to HOD";
+            throw new ExecException(msg, errCode, PigException.REMOTE_ENVIRONMENT, e);
         }
     }
 
@@ -463,7 +480,9 @@
         try {
             bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(localFile)));
         } catch (Exception e){
-            throw new ExecException("Failed to create local hadoop file " + localFile, e);
+            int errCode = 4008;
+            String msg = "Failed to create local hadoop file " + localFile;
+            throw new ExecException(msg, errCode, PigException.USER_ENVIRONMENT, e);
         }
 
         try {
@@ -476,7 +495,9 @@
             br.close();
             bw.close();
         } catch (Exception e){
-            throw new ExecException("Failed to copy data to local hadoop file " + localFile, e);
+            int errCode = 4009;
+            String msg = "Failed to copy data to local hadoop file " + localFile;
+            throw new ExecException(msg, errCode, PigException.USER_ENVIRONMENT, e);
         }
 
         return localDir;
@@ -515,6 +536,7 @@
                     errMsg = br.readLine();
                     br.close();
                 } catch (IOException ioe) {}
+                int errCode = 6011;
                 StringBuilder msg = new StringBuilder("Failed to run command ");
                 msg.append(cmdToString(cmdarray));
                 msg.append(" on server ");
@@ -523,10 +545,13 @@
                 msg.append(rc);
                 msg.append("; error: ");
                 msg.append(errMsg);
-                throw new ExecException(msg.toString());
+                throw new ExecException(msg.toString(), errCode, PigException.REMOTE_ENVIRONMENT);
             }
         } catch (Exception e){
-            throw new ExecException(e);
+            if(e instanceof ExecException) throw (ExecException)e;
+            int errCode = 6012;
+            String msg = "Unable to run command: " + cmdToString(cmdarray) + " on server " + server;
+            throw new ExecException(msg, errCode, PigException.REMOTE_ENVIRONMENT, e);
         }
 
         return p;

Modified: hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/CombinerOptimizer.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/CombinerOptimizer.java?rev=737239&r1=737238&r2=737239&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/CombinerOptimizer.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/CombinerOptimizer.java Fri Jan 23 23:07:30 2009
@@ -18,25 +18,21 @@
 package org.apache.pig.backend.hadoop.executionengine.mapReduceLayer;
 
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import org.apache.pig.PigException;
 import org.apache.pig.FuncSpec;
 import org.apache.pig.data.DataType;
-import org.apache.pig.backend.executionengine.ExecException;
-import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MRCompiler.LastInputStreamingOptimizer;
 import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.plans.MROperPlan;
 import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.plans.MROpPlanVisitor;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.POPrinter;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POUserFunc;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POProject;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhyPlanVisitor;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhysicalPlan;
-import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PlanPrinter;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.PODistinct;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POForEach;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POFilter;
@@ -52,7 +48,6 @@
 import org.apache.pig.impl.plan.PlanException;
 import org.apache.pig.impl.plan.PlanWalker;
 import org.apache.pig.impl.plan.VisitorException;
-import org.apache.pig.impl.util.Pair;
 
 /**
  * Optimize map reduce plans to use the combiner where possible.
@@ -281,7 +276,9 @@
                     // there should be only one successor to package
                     sucs.get(0).setInputs(packList);
                 } catch (Exception e) {
-                    throw new VisitorException(e);
+                    int errCode = 2018;
+                    String msg = "Internal error. Unable to introduce the combiner for optimization.";
+                    throw new VisitorException(msg, errCode, PigException.BUG, e);
                 }
             }
         }
@@ -517,7 +514,9 @@
         for (int i = 0; i < plans.size(); i++) {
                 List<PhysicalOperator> leaves = plans.get(i).getLeaves();
                 if (leaves == null || leaves.size() != 1) {
-                    throw new RuntimeException("Expected to find plan with single leaf!");
+                    int errCode = 2019;
+                    String msg = "Expected to find plan with single leaf. Found " + leaves.size() + " leaves.";
+                    throw new PlanException(msg, errCode, PigException.BUG);
                 }
                 PhysicalOperator leaf = leaves.get(0);
                 // the combine plan could have an extra foreach inner plan
@@ -593,21 +592,25 @@
         fe.addInputPlan(newForEachInnerPlan, false);
     }
 
-    private void changeFunc(POForEach fe, PhysicalPlan plan, byte type) {
+    private void changeFunc(POForEach fe, PhysicalPlan plan, byte type) throws PlanException {
         List<PhysicalOperator> leaves = plan.getLeaves();
         if (leaves == null || leaves.size() != 1) {
-            throw new RuntimeException("Expected to find plan with single leaf!");
+            int errCode = 2019;
+            String msg = "Expected to find plan with single leaf. Found " + leaves.size() + " leaves.";
+            throw new PlanException(msg, errCode, PigException.BUG);
         }
 
         PhysicalOperator leaf = leaves.get(0);
         if (!(leaf instanceof POUserFunc)) {
-            throw new RuntimeException("Expected to find plan with UDF leaf!");
+            int errCode = 2020;
+            String msg = "Expected to find plan with UDF leaf. Found " + leaf.getClass().getSimpleName();
+            throw new PlanException(msg, errCode, PigException.BUG);
         }
         POUserFunc func = (POUserFunc)leaf;
         func.setAlgebraicFunction(type);
     }
 
-    private void fixUpRearrange(POLocalRearrange rearrange) throws ExecException {
+    private void fixUpRearrange(POLocalRearrange rearrange) throws PlanException {
         // Set the projection to be the key
         PhysicalPlan newPlan = new PhysicalPlan();
         String scope = rearrange.getOperatorKey().scope;