Yingyi Bu has uploaded a new change for review.
https://asterix-gerrit.ics.uci.edu/1410
Change subject: Use a file to store the map from error codes to error messages.
......................................................................
Use a file to store the map from error codes to error messages.
Change-Id: I344903a9961469b62a951a9095514bf671ff11ee
---
M
asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
A asterixdb/asterix-common/src/main/resources/errormsg/en.properties
M
asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/InvalidExpressionException.java
M
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/exceptions/UnderflowException.java
M
hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ErrorMessageUtil.java
5 files changed, 100 insertions(+), 62 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb
refs/changes/10/1410/1
diff --git
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
index 743d5fb..e2a5851 100644
---
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
+++
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
@@ -18,8 +18,16 @@
*/
package org.apache.asterix.common.exceptions;
+import java.io.File;
+import java.io.IOError;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import org.apache.hyracks.api.util.ErrorMessageUtil;
// Error code:
// 0 --- 999: runtime errors
@@ -28,6 +36,7 @@
// 3000 ---- 3999: feed errors
// 4000 ---- 4999: lifecycle management errors
public class ErrorCode {
+ private static final String RESOURCE_PATH = File.separator + "errormsg" +
File.separator + "en.properties";
public static final String ASTERIX = "ASX";
// Extension errors
@@ -55,65 +64,12 @@
public static final int ERROR_COMPILATION_TYPE_INCOMPATIBLE = 1003;
public static final int ERROR_COMPILATION_TYPE_UNSUPPORTED = 1004;
public static final int ERROR_COMPILATION_TYPE_ITEM = 1005;
- public static final int ERROR_COMPILATION_INVALID_EXPRESSION = 1006;
- public static final int ERROR_COMPILATION_INVALID_PARAMETER_NUMBER = 1007;
- public static final int ERROR_COMPILATION_DUPLICATE_FIELD_NAME = 1008;
+ public static final int ERROR_COMPILATION_DUPLICATE_FIELD_NAME = 1006;
+ public static final int ERROR_COMPILATION_INVALID_EXPRESSION = 1007;
+ public static final int ERROR_COMPILATION_INVALID_PARAMETER_NUMBER = 1008;
- private static final String ERROR_MESSAGE_ID_CONFLICT = "Two Extensions
share the same Id: %1$s";
- private static final String ERROR_MESSAGE_COMPONENT_CONFLICT = "Extension
Conflict between %1$s and %2$s both "
- + "extensions extend %3$s";
- private static final String ERROR_MESSAGE_TYPE_MISMATCH = "Type mismatch:
function %1$s expects"
- + " its %2$s input parameter to be type %3$s, but the actual input
type is %4$s";
- private static final String ERROR_MESSAGE_TYPE_INCOMPATIBLE = "Type
incompatibility: function %1$s gets"
- + " incompatible input values: %2$s and %3$s";
- private static final String ERROR_MESSAGE_TYPE_UNSUPPORTED = "Unsupported
type: %1$s"
- + " cannot process input type %2$s";
- private static final String ERROR_MESSAGE_TYPE_ITEM = "Invalid item type:
function %1$s"
- + " cannot process item type %2$s in an input array (or multiset)";
- private static final String ERROR_MESSAGE_INVALID_FORMAT = "Invalid format
for %1$s in %2$s";
- private static final String ERROR_MESSAGE_OVERFLOW = "Overflow happend in
%1$s";
- private static final String ERROR_MESSAGE_UNDERFLOW = "Underflow happend
in %1$s";
- private static final String ERROR_MESSAGE_INJECTED_FAILURE = "Injected
failure in %1$s";
- private static final String ERROR_MESSAGE_NEGATIVE_VALUE = "Invalid value:
function %1$s expects"
- + " its %2$s input parameter to be a non-negative value, but gets
%3$s";
- private static final String ERROR_MESSAGE_OUT_OF_BOUND = "Index out of
bound in %1$s: %2$s";
- private static final String ERROR_MESSAGE_COERCION = "Invalid implicit
scalar to collection coercion in %1$s";
- private static final String ERROR_MESSAGE_DUPLICATE_FIELD = "Duplicate
field name \"%1$s\"";
- private static final String ERROR_MESSAGE_INVALID_EXPRESSION = "Invalid
expression: function %1$s expects"
- + " its %2$s input parameter to be a %3$s expression, but the
actual expression is %4$s";
- private static final String ERROR_MESSAGE_INVALID_PARAMETER_NUMBER =
"Invalid parameter number: function %1$s "
- + "cannot take %2$s parameters";
-
- private static Map<Integer, String> errorMessageMap = new HashMap<>();
-
- static {
- // runtime errors
- errorMessageMap.put(ERROR_TYPE_MISMATCH, ERROR_MESSAGE_TYPE_MISMATCH);
- errorMessageMap.put(ERROR_TYPE_INCOMPATIBLE,
ERROR_MESSAGE_TYPE_INCOMPATIBLE);
- errorMessageMap.put(ERROR_TYPE_ITEM, ERROR_MESSAGE_TYPE_ITEM);
- errorMessageMap.put(ERROR_TYPE_UNSUPPORTED,
ERROR_MESSAGE_TYPE_UNSUPPORTED);
- errorMessageMap.put(ERROR_INVALID_FORMAT,
ERROR_MESSAGE_INVALID_FORMAT);
- errorMessageMap.put(ERROR_OVERFLOW, ERROR_MESSAGE_OVERFLOW);
- errorMessageMap.put(ERROR_UNDERFLOW, ERROR_MESSAGE_UNDERFLOW);
- errorMessageMap.put(ERROR_INJECTED_FAILURE,
ERROR_MESSAGE_INJECTED_FAILURE);
- errorMessageMap.put(ERROR_NEGATIVE_VALUE,
ERROR_MESSAGE_NEGATIVE_VALUE);
- errorMessageMap.put(ERROR_OUT_OF_BOUND, ERROR_MESSAGE_OUT_OF_BOUND);
- errorMessageMap.put(ERROR_COERCION, ERROR_MESSAGE_COERCION);
- errorMessageMap.put(ERROR_DUPLICATE_FIELD_NAME,
ERROR_MESSAGE_DUPLICATE_FIELD);
-
- // compilation errors
- errorMessageMap.put(ERROR_COMPILATION_TYPE_MISMATCH,
ERROR_MESSAGE_TYPE_MISMATCH);
- errorMessageMap.put(ERROR_COMPILATION_TYPE_INCOMPATIBLE,
ERROR_MESSAGE_TYPE_INCOMPATIBLE);
- errorMessageMap.put(ERROR_COMPILATION_TYPE_ITEM,
ERROR_MESSAGE_TYPE_ITEM);
- errorMessageMap.put(ERROR_COMPILATION_TYPE_UNSUPPORTED,
ERROR_MESSAGE_TYPE_UNSUPPORTED);
- errorMessageMap.put(ERROR_COMPILATION_INVALID_EXPRESSION,
ERROR_MESSAGE_INVALID_EXPRESSION);
- errorMessageMap.put(ERROR_COMPILATION_INVALID_PARAMETER_NUMBER,
ERROR_MESSAGE_INVALID_PARAMETER_NUMBER);
- errorMessageMap.put(ERROR_COMPILATION_DUPLICATE_FIELD_NAME,
ERROR_MESSAGE_DUPLICATE_FIELD);
-
- // lifecycle management errors
- errorMessageMap.put(ERROR_EXTENSION_ID_CONFLICT,
ERROR_MESSAGE_ID_CONFLICT);
- errorMessageMap.put(ERROR_EXTENSION_COMPONENT_CONFLICT,
ERROR_MESSAGE_COMPONENT_CONFLICT);
- }
+ // Loads the map that maps error codes to error message templates.
+ private static Map<Integer, String> errorMessageMap =
ErrorMessageUtil.loadErrorMap(RESOURCE_PATH);
private ErrorCode() {
}
diff --git a/asterixdb/asterix-common/src/main/resources/errormsg/en.properties
b/asterixdb/asterix-common/src/main/resources/errormsg/en.properties
new file mode 100644
index 0000000..823ef10
--- /dev/null
+++ b/asterixdb/asterix-common/src/main/resources/errormsg/en.properties
@@ -0,0 +1,35 @@
+#
+# 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.
+#
+
+4001 = Two Extensions share the same Id: %1$s
+4002 = Extension Conflict between %1$s and %2$s both extensions extend %3$s
+2,1002 = Type mismatch: function %1$s expects its %2$s input parameter to be
type %3$s, but the actual input type is %4$s
+3,1003 = Type incompatibility: function %1$s gets incompatible input values:
%2$s and %3$s
+4,1004 = Unsupported type: %1$s cannot process input type %2$s
+5,1005 = Invalid item type: function %1$s cannot process item type %2$s in an
input array (or multiset)
+6 = Invalid format for %1$s in %2$s
+7 = Overflow happend in %1$s
+8=Underflow happend in %1$s
+9=Injected failure in %1$s
+10=Invalid value: function %1$s expects its %2$s input parameter to be a
non-negative value, but gets %3$s
+11=Index out of bound in %1$s: %2$s
+12=Invalid implicit scalar to collection coercion in %1$s
+13,1006=Duplicate field name \"%1$s\"
+1007=Invalid expression: function %1$s expects its %2$s input parameter to be
a %3$s expression, but the actual expression is %4$s
+1008=Invalid parameter number: function %1$s cannot take %2$s parameters
diff --git
a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/InvalidExpressionException.java
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/InvalidExpressionException.java
index a4b3a32..c381b7b 100644
---
a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/InvalidExpressionException.java
+++
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/InvalidExpressionException.java
@@ -34,14 +34,14 @@
public InvalidExpressionException(FunctionIdentifier fid, int index,
ILogicalExpression actualExpr,
LogicalExpressionTag... exprKinds) {
- super(ErrorCode.ERROR_COMPILATION_TYPE_INCOMPATIBLE, fid.getName(),
indexToPosition(index),
+ super(ErrorCode.ERROR_COMPILATION_INVALID_EXPRESSION, fid.getName(),
indexToPosition(index),
actualExpr.toString(),
toExpectedTypeString(exprKinds));
}
public InvalidExpressionException(String functionName, int index,
ILogicalExpression actualExpr,
LogicalExpressionTag... exprKinds) {
- super(ErrorCode.ERROR_COMPILATION_TYPE_INCOMPATIBLE, functionName,
indexToPosition(index),
+ super(ErrorCode.ERROR_COMPILATION_INVALID_EXPRESSION, functionName,
indexToPosition(index),
actualExpr.toString(),
toExpectedTypeString(exprKinds));
}
diff --git
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/exceptions/UnderflowException.java
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/exceptions/UnderflowException.java
index fede04f..cb39ab2 100644
---
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/exceptions/UnderflowException.java
+++
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/exceptions/UnderflowException.java
@@ -27,12 +27,12 @@
// Underflow.
public UnderflowException(FunctionIdentifier fid) {
- super(ErrorCode.ERROR_OVERFLOW, fid.getName());
+ super(ErrorCode.ERROR_UNDERFLOW, fid.getName());
}
// Underflow.
public UnderflowException(String functionName) {
- super(ErrorCode.ERROR_OVERFLOW, functionName);
+ super(ErrorCode.ERROR_UNDERFLOW, functionName);
}
}
diff --git
a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ErrorMessageUtil.java
b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ErrorMessageUtil.java
index fd1e850..b08b2a1 100644
---
a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ErrorMessageUtil.java
+++
b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/ErrorMessageUtil.java
@@ -21,21 +21,68 @@
package org.apache.hyracks.api.util;
+import static com.sun.tools.doclint.Entity.prop;
+
+import java.io.IOError;
+import java.io.IOException;
+import java.io.InputStream;
import java.io.Serializable;
import java.util.Formatter;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
+
+import org.apache.hyracks.api.exceptions.ErrorCode;
public class ErrorMessageUtil {
private static final Logger LOGGER =
Logger.getLogger(ErrorMessageUtil.class.getName());
public static final String NONE = "";
+ private static final String COMMA = ",";
private ErrorMessageUtil() {
}
/**
+ * Loads the mapping from error codes to error messages from a properties
file.
+ * The key of properties is in the form of comma-separated error codes and
the value is the corresponding
+ * error message template.
+ *
+ * Example entries in the properties file:
+ * 4002=Extension Conflict between %1$s and %2$s both extensions extend
%3$s
+ * 2,1002 = Type mismatch: function %1$s expects its %2$s input parameter
to be type %3$s
+ *
+ * @param path,
+ * the path of the properties file
+ * @return the map that maps error codes (integers) to error message
templates (strings).
+ */
+ public static Map<Integer, String> loadErrorMap(String path) {
+ Properties prop = new Properties();
+ Map<Integer, String> errorMessageMap = new HashMap<>();
+ try (InputStream resourceStream =
ErrorCode.class.getResourceAsStream(path)) {
+ prop.load(resourceStream);
+ for (Map.Entry<Object, Object> entry : prop.entrySet()) {
+ String key = (String) entry.getKey();
+ String msg = (String) entry.getValue();
+ if (key.contains(COMMA)) {
+ String[] codes = key.split(COMMA);
+ for (String code : codes) {
+ errorMessageMap.put(Integer.parseInt(code), msg);
+ }
+ } else {
+ errorMessageMap.put(Integer.parseInt(key), msg);
+ }
+ }
+ return errorMessageMap;
+ } catch (IOException e) {
+ throw new IOError(e);
+ }
+ }
+
+ /**
* formats a error message
* Example:
* formatMessage(HYRACKS, ErrorCode.UNKNOWN, "%1$s -- %2$s", "one", "two")
returns "HYR0000: one -- two"
--
To view, visit https://asterix-gerrit.ics.uci.edu/1410
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I344903a9961469b62a951a9095514bf671ff11ee
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Yingyi Bu <[email protected]>