[ 
https://issues.apache.org/jira/browse/PIG-1611?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Thejas M Nair updated PIG-1611:
-------------------------------

    Attachment: PIG-1611.1.patch

Attaching an incomplete version of the patch for review. I am looking for 
feedback on this design/plan -

- An interface ErrorCode has been created within PigException class. 
PigException and subclasses will create an enum class that will implement this 
interface. An example of enum implementing this interface is 
UnionOnSchemaSetException in 
src/org/apache/pig/impl/logicalLayer/validators/UnionOnSchemaSetException.java  
.

- If one enum class was used for all error codes, most patches would end up 
modifying this same file at same location, and that will result in conflicts 
while merging the changes. So I chose to have an enum class in each 
PigException subclass to reduce the chances of that happening. 

- The enum constructor would take the arguments (String msg, byte errorType, 
boolean retriable) . There can be another constructors that just takes the 
(String msg)  or (String msg, byte errorType) as arguments if user wants 
defaults for errorType (BUG) and retriable (false). Having errorType and 
retriable information along with the enum will make it easier to generate the 
documentation for error codes. 
for example -
{code}
       SCH_MERGE_ER("Error creating merged schemas for union-onschema 
operator", PigException.INPUT, false),
       ERROR_ADDING_UNION_OP("Error adding union operator ", PigException.BUG, 
false);
{code}

- Example of class using new exception constructor is in 
src/org/apache/pig/impl/logicalLayer/UnionOnSchemaSetter.java .

- Existing exception constructors that use error code number are being 
deprecated, so that developers use the new constructors that use. This patch 
will not change current code that is already using old constructors.

- Other exception classes need to be updated to have the ErrorCode enum and new 
constructors. 


> use enums for error code
> ------------------------
>
>                 Key: PIG-1611
>                 URL: https://issues.apache.org/jira/browse/PIG-1611
>             Project: Pig
>          Issue Type: Sub-task
>            Reporter: Thejas M Nair
>             Fix For: 0.9.0
>
>         Attachments: PIG-1611.1.patch
>
>
> Pig code is using integer constants for error code, and the value of the 
> error code is reserved using 
> http://wiki.apache.org/pig/PigErrorHandlingFunctionalSpecification .
> This process is cumbersome and error prone.
> It will be better to use enum values instead. The enum value can contain the 
> error message and encapsulate the error code. 
> For example -
> {code}
> Replace 
> throw new SchemaMergeException("Error in merging schema", 2124, 
> PigException.BUG); 
> with
> throw new SchemaMergeException(SCHEMA_MERGE_EX, PigException.BUG); 
> {code}
> Where SCHEMA_MERGE_EX belongs to a error codes enum. We can use the ordinal 
> value of the enum and an offset to determine the error code. 
> The error code will be passed through the constructor of the enum.
> {code}
> SCHEMA_MERGE_EX("Error in merging schema");
> {code}
> For documentation, the error code and error messages can be dumped using code 
> that uses the enum error code class.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to