Skip to content
Permalink
Browse files
[NO ISSUE][MISC] HTTP error handling, exception message cleanup
Change-Id: If8fc109aee55571aff4a87029cad2a7a0c516d0c
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/15023
Reviewed-by: Hussain Towaileb <hussainht@gmail.com>
Tested-by: Michael Blow <mblow@apache.org>
  • Loading branch information
mblow committed Feb 4, 2022
1 parent cd050c8 commit 81c526671dfca70ee1ebae9c64677e117a212362
Showing 19 changed files with 207 additions and 189 deletions.
@@ -236,7 +236,7 @@ public static void validateIndexFieldType(IndexType indexType, IAType fieldType,
break;
default:
throw new CompilationException(ErrorCode.COMPILATION_ERROR, sourceLoc,
"The field \"" + displayFieldName + "\" which is of type " + fieldType.getTypeTag()
"The field '" + displayFieldName + "' which is of type " + fieldType.getTypeTag()
+ " cannot be indexed using the BTree index.");
}
break;
@@ -251,14 +251,14 @@ public static void validateIndexFieldType(IndexType indexType, IAType fieldType,
break;
default:
throw new CompilationException(ErrorCode.COMPILATION_ERROR, sourceLoc,
"The field \"" + displayFieldName + "\" which is of type " + fieldType.getTypeTag()
"The field '" + displayFieldName + "' which is of type " + fieldType.getTypeTag()
+ " cannot be indexed using the RTree index.");
}
break;
case LENGTH_PARTITIONED_NGRAM_INVIX:
if (fieldType.getTypeTag() != ATypeTag.STRING) {
throw new CompilationException(ErrorCode.COMPILATION_ERROR, sourceLoc,
"The field \"" + displayFieldName + "\" which is of type " + fieldType.getTypeTag()
"The field '" + displayFieldName + "' which is of type " + fieldType.getTypeTag()
+ " cannot be indexed using the Length Partitioned N-Gram index.");
}
break;
@@ -270,14 +270,14 @@ public static void validateIndexFieldType(IndexType indexType, IAType fieldType,
break;
default:
throw new CompilationException(ErrorCode.COMPILATION_ERROR, sourceLoc,
"The field \"" + displayFieldName + "\" which is of type " + fieldType.getTypeTag()
"The field '" + displayFieldName + "' which is of type " + fieldType.getTypeTag()
+ " cannot be indexed using the Length Partitioned Keyword index.");
}
break;
case SINGLE_PARTITION_NGRAM_INVIX:
if (fieldType.getTypeTag() != ATypeTag.STRING) {
throw new CompilationException(ErrorCode.COMPILATION_ERROR, sourceLoc,
"The field \"" + displayFieldName + "\" which is of type " + fieldType.getTypeTag()
"The field '" + displayFieldName + "' which is of type " + fieldType.getTypeTag()
+ " cannot be indexed using the N-Gram index.");
}
break;
@@ -289,7 +289,7 @@ public static void validateIndexFieldType(IndexType indexType, IAType fieldType,
break;
default:
throw new CompilationException(ErrorCode.COMPILATION_ERROR, sourceLoc,
"The field \"" + displayFieldName + "\" which is of type " + fieldType.getTypeTag()
"The field '" + displayFieldName + "' which is of type " + fieldType.getTypeTag()
+ " cannot be indexed using the Keyword index.");
}
break;
@@ -83,7 +83,7 @@ protected void get(IServletRequest request, IServletResponse response) throws IO
}
JSONUtil.writeNode(responseWriter, json);
} catch (IllegalArgumentException e) { // NOSONAR - exception not logged or rethrown
response.setStatus(HttpResponseStatus.NOT_FOUND);
sendError(response, HttpResponseStatus.NOT_FOUND);
} catch (Exception e) {
LOGGER.log(Level.INFO, "exception thrown for " + request, e);
response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
@@ -79,10 +79,10 @@ protected void get(IServletRequest request, IServletResponse response) throws IO
} catch (RejectedExecutionException e) {
// we must be shutting down, return 503
LOGGER.info("RejectedExecutionException while servicing request; returning 503", e);
sendError(response, HttpResponseStatus.SERVICE_UNAVAILABLE, null);
sendError(response, HttpResponseStatus.SERVICE_UNAVAILABLE);
} catch (Exception e) {
LOGGER.warn("exception while servicing request; returning 500", e);
sendError(response, HttpResponseStatus.INTERNAL_SERVER_ERROR, e.toString());
sendError(response, HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
responseWriter.flush();
}
@@ -295,7 +295,8 @@ private void writeException(Exception e, IServletResponse response) {
responseWriter.flush();
}

protected boolean isRequestPermittedForWrite(IServletRequest request, IServletResponse response) {
protected boolean isRequestPermittedForWrite(IServletRequest request, IServletResponse response)
throws IOException {
if (!isRequestOnLoopback(request)) {
rejectForbidden(response);
return false;
@@ -313,20 +314,21 @@ protected boolean isRequestOnLoopback(IServletRequest request) {
}
}

protected static void rejectForbidden(IServletResponse response) {
response.setStatus(HttpResponseStatus.FORBIDDEN);
response.writer().write("{ \"error\": \"Forbidden\" }");
protected void rejectForbidden(IServletResponse response) throws IOException {
// TODO: why this JSON format, do we use this anywhere else?
sendError(response, HttpUtil.ContentType.APPLICATION_JSON, HttpResponseStatus.FORBIDDEN,
"{ \"error\": \"Forbidden\" }");
}

@Override
protected void post(IServletRequest request, IServletResponse response) {
protected void post(IServletRequest request, IServletResponse response) throws IOException {
if (isRequestPermittedForWrite(request, response)) {
handleModification(request, response, LibraryOperation.UPSERT);
}
}

@Override
protected void delete(IServletRequest request, IServletResponse response) {
protected void delete(IServletRequest request, IServletResponse response) throws IOException {
if (isRequestPermittedForWrite(request, response)) {
handleModification(request, response, LibraryOperation.DELETE);
}
@@ -1248,8 +1248,8 @@ protected void doCreateIndex(MetadataProvider metadataProvider, CreateIndexState
// allow overriding the type of the closed-field only if CAST modifier is used
if (!stmtCreateIndex.hasCastDefaultNull()) {
throw new CompilationException(ErrorCode.COMPILATION_ERROR,
indexedElement.getSourceLocation(), "Typed index on \"" + projectPath
+ "\" field could be created only for open datatype");
indexedElement.getSourceLocation(), "Typed index on '" + projectPath
+ "' field could be created only for open datatype");
}
}
}
@@ -1631,9 +1631,9 @@ private void doCreateIndexImpl(IHyracksClientConnection hcc, MetadataProvider me
&& !existingIndexKeyFieldTypes.equals(indexKeyFieldTypes)) {
throw new CompilationException(ErrorCode.COMPILATION_ERROR, sourceLoc,
"Cannot create index " + index.getIndexName() + " , enforced index "
+ existingIndex.getIndexName() + " on field \""
+ StringUtils.join(indexKeyFieldNames, ',')
+ "\" is already defined with type \"" + existingIndexKeyFieldTypes + "\"");
+ existingIndex.getIndexName() + " on field '"
+ StringUtils.join(indexKeyFieldNames, ',') + "' is already defined with type '"
+ existingIndexKeyFieldTypes + "'");
}
}
}
@@ -227,7 +227,7 @@ private static ExtractedResult extract(InputStream resultStream, EnumSet<ResultF
final String fieldName = fieldNameIter.next();
final ResultField fieldKind = ResultField.ofFieldName(fieldName.split("-")[0]);
if (fieldKind == null) {
throw new AsterixException("Unanticipated field \"" + fieldName + "\"");
throw new AsterixException("Unanticipated field '" + fieldName + "'");
}
if (!resultFields.contains(fieldKind)) {
continue;
@@ -498,7 +498,7 @@
<test-case FilePath="exception">
<compilation-unit name="issue_255_create_dataset_error_1">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1014: Field "name" is not found (in line 34, at column 1)</expected-error>
<expected-error>ASX1014: Field 'name' is not found (in line 34, at column 1)</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="exception">
@@ -511,56 +511,56 @@
<test-case FilePath="exception">
<compilation-unit name="issue_255_create_feed_error">
<output-dir compare="Text">none</output-dir>
<expected-error>org.json.JSONException: JSONObject["summary"] not found</expected-error>
<expected-error>org.json.JSONException: JSONObject['summary'] not found</expected-error>
</compilation-unit>
</test-case> -->
<!-- This case should be fixed to return a proper message rather than NPE -->
<test-case FilePath="exception">
<compilation-unit name="issue_266_create_dataset_error_1">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1014: Field "point" is not found (in line 34, at column 1)</expected-error>
<expected-error>ASX1014: Field 'point' is not found (in line 34, at column 1)</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="exception">
<compilation-unit name="issue_266_create_dataset_error_2">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1021: The primary key field "id" cannot be nullable (in line 34, at column 1)</expected-error>
<expected-error>ASX1021: The primary key field 'id' cannot be nullable (in line 34, at column 1)</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="exception">
<compilation-unit name="issue_384_create_index_error_1">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1079: Compilation error: The field "[loc]" which is of type point cannot be indexed using the BTree index. (in line 37, at column 33)</expected-error>
<expected-error>ASX1079: Compilation error: The field '[loc]' which is of type point cannot be indexed using the BTree index. (in line 37, at column 33)</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="exception">
<compilation-unit name="issue_384_create_index_error_2">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1079: Compilation error: The field "[age]" which is of type integer cannot be indexed using the RTree index. (in line 37, at column 33)</expected-error>
<expected-error>ASX1079: Compilation error: The field '[age]' which is of type integer cannot be indexed using the RTree index. (in line 37, at column 33)</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="exception">
<compilation-unit name="issue_384_create_index_error_3">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1079: Compilation error: The field "[loc]" which is of type point cannot be indexed using the Length Partitioned Keyword index. (in line 37, at column 33)</expected-error>
<expected-error>ASX1079: Compilation error: The field '[loc]' which is of type point cannot be indexed using the Length Partitioned Keyword index. (in line 37, at column 33)</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="exception">
<compilation-unit name="issue_384_create_index_error_4">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1079: Compilation error: The field "[loc]" which is of type point cannot be indexed using the Length Partitioned Keyword index. (in line 37, at column 33)</expected-error>
<expected-error>ASX1079: Compilation error: The field '[loc]' which is of type point cannot be indexed using the Length Partitioned Keyword index. (in line 37, at column 33)</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="exception">
<compilation-unit name="issue_384_create_index_error_5">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1079: Compilation error: The field "[loc]" which is of type point cannot be indexed using the Length Partitioned N-Gram index. (in line 37, at column 33)</expected-error>
<expected-error>ASX1079: Compilation error: The field '[loc]' which is of type point cannot be indexed using the Length Partitioned N-Gram index. (in line 37, at column 33)</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="exception">
<compilation-unit name="issue_384_create_index_error_6">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1079: Compilation error: The field "[loc]" which is of type point cannot be indexed using the Length Partitioned N-Gram index. (in line 37, at column 33)</expected-error>
<expected-error>ASX1079: Compilation error: The field '[loc]' which is of type point cannot be indexed using the Length Partitioned N-Gram index. (in line 37, at column 33)</expected-error>
</compilation-unit>
</test-case>
</test-group>
@@ -111,7 +111,7 @@
<compilation-unit name="no_fieldname_constr">
<output-dir compare="Text">no_fieldname_constr</output-dir>
<expected-warn>Encountered a cross product join (in line 27, at column 22)</expected-warn>
<expected-warn>Duplicate field name "a" (in line 31, at column 24)</expected-warn>
<expected-warn>Duplicate field name 'a' (in line 31, at column 24)</expected-warn>
</compilation-unit>
</test-case>
<test-case FilePath="objects">
@@ -199,7 +199,7 @@
<test-case FilePath="objects" check-warnings="true">
<compilation-unit name="closed-closed-fieldname-conflict_issue173">
<output-dir compare="Text">closed-closed-fieldname-conflict_issue173</output-dir>
<expected-warn>Duplicate field name "name" (in line 30, at column 16)</expected-warn>
<expected-warn>Duplicate field name 'name' (in line 30, at column 16)</expected-warn>
</compilation-unit>
</test-case>
<test-case FilePath="objects" check-warnings="true">
@@ -227,15 +227,15 @@
<test-case FilePath="objects" check-warnings="true">
<compilation-unit name="object_duplicate_fields">
<output-dir compare="Text">object_duplicate_fields</output-dir>
<expected-warn>Duplicate field name "name" (in line 27, at column 1)</expected-warn>
<expected-warn>Duplicate field name "Name" (in line 29, at column 1)</expected-warn>
<expected-warn>Duplicate field name "name" (in line 31, at column 1)</expected-warn>
<expected-warn>Duplicate field name "name" (in line 22, at column 30)</expected-warn>
<expected-warn>Duplicate field name "id" (in line 22, at column 56)</expected-warn>
<expected-warn>Duplicate field name "f1" (in line 22, at column 70)</expected-warn>
<expected-warn>Duplicate field name "id" (in line 22, at column 56)</expected-warn>
<expected-warn>Duplicate field name "f1" (in line 22, at column 83)</expected-warn>
<expected-warn>Duplicate field name "fname1" (in line 25, at column 45)</expected-warn>
<expected-warn>Duplicate field name 'name' (in line 27, at column 1)</expected-warn>
<expected-warn>Duplicate field name 'Name' (in line 29, at column 1)</expected-warn>
<expected-warn>Duplicate field name 'name' (in line 31, at column 1)</expected-warn>
<expected-warn>Duplicate field name 'name' (in line 22, at column 30)</expected-warn>
<expected-warn>Duplicate field name 'id' (in line 22, at column 56)</expected-warn>
<expected-warn>Duplicate field name 'f1' (in line 22, at column 70)</expected-warn>
<expected-warn>Duplicate field name 'id' (in line 22, at column 56)</expected-warn>
<expected-warn>Duplicate field name 'f1' (in line 22, at column 83)</expected-warn>
<expected-warn>Duplicate field name 'fname1' (in line 25, at column 45)</expected-warn>
</compilation-unit>
</test-case>
</test-group>
@@ -1,6 +1,6 @@
{
"errors": [{
"code": 1, "msg": "ASX0047: Invalid value for parameter \"format\": foo" }
"code": 1, "msg": "ASX0047: Invalid value for parameter 'format': foo" }
],
"status": "fatal",
"metrics": {
@@ -23,7 +23,7 @@
\s*\Q"warnings": [{\E\s*
\s*\Q"code": 1,\E\s*\Q"msg": "ASX1107: Unexpected hint: hint. None expected at this location\E[^}]+\Q}\E\s*
\s*\Q,{\E\s*
\s*\Q"code": 1,\E\s*\Q"msg": "ASX1006: Duplicate field name \"a\"\E[^}]+\Q}\E\s*
\s*\Q"code": 1,\E\s*\Q"msg": "ASX1006: Duplicate field name 'a'\E[^}]+\Q}\E\s*
\s*\Q,{\E\s*
\s*\Q"code": 1,\E\s*\Q"msg": "ASX0002: Type mismatch: function isbitset expects its 2nd input parameter to be of type bigint or array, but the actual input type is string\E[^}]+\Q}\E\s*
\s*\Q],\E
@@ -6,7 +6,7 @@
\s*\Q"results": [ {\E.*warnings\Q": [{\E\s*
\s*\Q"code": 1,\E\s*\Q"msg": "ASX1107: Unexpected hint: hint. None expected at this location\E[^}]+\Q}\E\s*
\s*\Q,{\E\s*
\s*\Q"code": 1,\E\s*\Q"msg": "ASX1006: Duplicate field name \"a\"\E[^}]+\Q}\E\s*
\s*\Q"code": 1,\E\s*\Q"msg": "ASX1006: Duplicate field name 'a'\E[^}]+\Q}\E\s*
\s*\Q],\E
\s*\Q"status": "success",\E
\s*\Q"metrics": {\E
@@ -23,7 +23,7 @@
\s*\Q"warnings": [{\E\s*
\s*\Q"code": 1,\E\s*\Q"msg": "ASX1107: Unexpected hint: hint. None expected at this location\E[^}]+\Q}\E\s*
\s*\Q,{\E\s*
\s*\Q"code": 1,\E\s*\Q"msg": "ASX1006: Duplicate field name \"a\"\E[^}]+\Q}\E\s*
\s*\Q"code": 1,\E\s*\Q"msg": "ASX1006: Duplicate field name 'a'\E[^}]+\Q}\E\s*
\s*\Q,{\E\s*
\s*\Q"code": 1,\E\s*\Q"msg": "ASX0002: Type mismatch: function isbitset expects its 2nd input parameter to be of type bigint or array, but the actual input type is string\E[^}]+\Q}\E\s*
\s*\Q],\E

0 comments on commit 81c5266

Please sign in to comment.