@Override public boolean apply(String input) { for (String context : e.getContextStrings()) { if (context.contains(input)) { return true; } } return false; } }).size() == expectedContexts.length);
private static QueryError.Range rangeOf(UserException uex) { Map<String, String> context = new HashMap<>(); for(String contextString: uex.getContextStrings()) { String[] split = contextString.split(" ", 2); if (split.length == 2) { context.put(split[0], split[1]); } else { context.put(contextString, null); } } try { final int startLine = Integer.parseInt(context.get(START_LINE_CONTEXT)); final int startColumn = Integer.parseInt(context.get(START_COLUMN_CONTEXT)); final int endLine = Integer.parseInt(context.get(END_LINE_CONTEXT)); final int endColumn = Integer.parseInt(context.get(END_COLUMN_CONTEXT)); // Providing the UI with the following convention: // Ranges are 1-based and inclusive. return new Range( startLine, startColumn, endLine , endColumn); } catch(NullPointerException | NumberFormatException e) { return null; } }
private static Response.Status getStatus(UserException uex) { List<String> contextList = uex.getContextStrings(); for (String context : contextList) { if (context.startsWith(RESPONSE_STATUS)) { try { String status = context.substring(RESPONSE_STATUS.length() + 1); return Response.Status.valueOf(status); } catch (Exception e) { // should not happen unless someone is passing an invalid status. In that case, ignore the context } } } if (uex.getErrorType() == ErrorType.CONCURRENT_MODIFICATION) { return CONFLICT; } return BAD_REQUEST; }
@Override public Response toResponse(UserException exception) { final String errorMessage = exception.getErrorType() == ErrorType.SYSTEM ? SYSTEM_ERROR_MSG : exception.getOriginalMessage(); return Response.status(getStatus(exception)) .entity(new ErrorMessageWithContext( errorMessage, removeStatus(exception.getContextStrings()), sendStackTrace ? GenericErrorMessage.printStackTrace(exception): null )) .type(APPLICATION_JSON_TYPE) .build(); }
if (ex.getErrorType() == ErrorType.OUT_OF_MEMORY) { if (context.containsHashAggregate()) { if (ex.getContextStrings().size() > 2 && ex.getContextStrings().get(1).equals(VectorizedHashAggOperator.OUT_OF_MEMORY_MSG)) {
@Override protected void describeMismatchSafely(final UserException e, final Description description) { description.appendText("UserException thrown was of type: ") .appendValue(e.getErrorType().toString()); if (expectedMessage != null) { description.appendText(" with message: \"") .appendText(e.getMessage()) .appendText("\""); } if (expectedContexts != null) { description.appendValueList(" with contexts {", ",", "}", e.getContextStrings()); } } }