public QueryParsingException(QueryParseContext parseContext, String msg, Throwable cause, Object... args) { super(msg, cause, args); setIndex(parseContext.index()); int lineNumber = UNKNOWN_POSITION; int columnNumber = UNKNOWN_POSITION; XContentParser parser = parseContext.parser(); if (parser != null) { XContentLocation location = parser.getTokenLocation(); if (location != null) { lineNumber = location.lineNumber; columnNumber = location.columnNumber; } } this.columnNumber = columnNumber; this.lineNumber = lineNumber; }
private static QueryBuilder parseQueryBuilder(QueryParseContext context, XContentLocation location) { try { return context.parseInnerQueryBuilder(); } catch (IOException e) { throw new ParsingException(location, "Failed to parse", e); } }
public static LessThanAssertion parse(XContentParser parser) throws IOException { XContentLocation location = parser.getTokenLocation(); Tuple<String,Object> stringObjectTuple = ParserUtils.parseTuple(parser); if (false == stringObjectTuple.v2() instanceof Comparable) { throw new IllegalArgumentException("lt section can only be used with objects that support natural ordering, found " + stringObjectTuple.v2().getClass().getSimpleName()); } return new LessThanAssertion(location, stringObjectTuple.v1(), stringObjectTuple.v2()); }
public static GreaterThanAssertion parse(XContentParser parser) throws IOException { XContentLocation location = parser.getTokenLocation(); Tuple<String,Object> stringObjectTuple = ParserUtils.parseTuple(parser); if (! (stringObjectTuple.v2() instanceof Comparable) ) { throw new IllegalArgumentException("gt section can only be used with objects that support natural ordering, found " + stringObjectTuple.v2().getClass().getSimpleName()); } return new GreaterThanAssertion(location, stringObjectTuple.v1(), stringObjectTuple.v2()); }
public static LessThanOrEqualToAssertion parse(XContentParser parser) throws IOException { XContentLocation location = parser.getTokenLocation(); Tuple<String,Object> stringObjectTuple = ParserUtils.parseTuple(parser); if (false == stringObjectTuple.v2() instanceof Comparable) { throw new IllegalArgumentException("lte section can only be used with objects that support natural ordering, found " + stringObjectTuple.v2().getClass().getSimpleName()); } return new LessThanOrEqualToAssertion(location, stringObjectTuple.v1(), stringObjectTuple.v2()); }
static ExecutableSection parse(XContentParser parser) throws IOException { ParserUtils.advanceToFieldName(parser); String section = parser.currentName(); XContentLocation location = parser.getTokenLocation(); try { ExecutableSection executableSection = parser.namedObject(ExecutableSection.class, section, null); parser.nextToken(); return executableSection; } catch (Exception e) { throw new IOException("Error parsing section starting at [" + location + "]", e); } }
public static GreaterThanEqualToAssertion parse(XContentParser parser) throws IOException { XContentLocation location = parser.getTokenLocation(); Tuple<String,Object> stringObjectTuple = ParserUtils.parseTuple(parser); if (! (stringObjectTuple.v2() instanceof Comparable) ) { throw new IllegalArgumentException("gte section can only be used with objects that support natural ordering, found " + stringObjectTuple.v2().getClass().getSimpleName()); } return new GreaterThanEqualToAssertion(location, stringObjectTuple.v1(), stringObjectTuple.v2()); }
public void testAddingDoWithoutWarningWithoutSkip() { int lineNumber = between(1, 10000); ClientYamlTestSection section = new ClientYamlTestSection(new XContentLocation(0, 0), "test"); section.setSkipSection(SkipSection.EMPTY); DoSection doSection = new DoSection(new XContentLocation(lineNumber, 0)); section.addExecutableSection(doSection); }
public void testAddingDoWithWarningWithSkip() { int lineNumber = between(1, 10000); ClientYamlTestSection section = new ClientYamlTestSection(new XContentLocation(0, 0), "test"); section.setSkipSection(new SkipSection(null, singletonList("warnings"), null)); DoSection doSection = new DoSection(new XContentLocation(lineNumber, 0)); doSection.setExpectedWarningHeaders(singletonList("foo")); section.addExecutableSection(doSection); }
public void testAddingDoWithWarningWithSkipButNotWarnings() { int lineNumber = between(1, 10000); ClientYamlTestSection section = new ClientYamlTestSection(new XContentLocation(0, 0), "test"); section.setSkipSection(new SkipSection(null, singletonList("yaml"), null)); DoSection doSection = new DoSection(new XContentLocation(lineNumber, 0)); doSection.setExpectedWarningHeaders(singletonList("foo")); Exception e = expectThrows(IllegalArgumentException.class, () -> section.addExecutableSection(doSection)); assertEquals("Attempted to add a [do] with a [warnings] section without a corresponding [skip] so runners that do not support the" + " [warnings] section can skip the test at line [" + lineNumber + "]", e.getMessage()); }
public SearchParseException(SearchContext context, String msg, @Nullable XContentLocation location, Throwable cause) { super(context, msg, cause); int lineNumber = UNKNOWN_POSITION; int columnNumber = UNKNOWN_POSITION; if (location != null) { if (location != null) { lineNumber = location.lineNumber; columnNumber = location.columnNumber; } } this.columnNumber = columnNumber; this.lineNumber = lineNumber; }
protected static void throwParsingExceptionOnMultipleFields(String queryName, XContentLocation contentLocation, String processedFieldName, String currentFieldName) { if (processedFieldName != null) { throw new ParsingException(contentLocation, "[" + queryName + "] query doesn't support multiple fields, found [" + processedFieldName + "] and [" + currentFieldName + "]"); } }
/** * Parses a query excluding the query element that wraps it */ public QueryBuilder parseInnerQueryBuilder() throws IOException { if (parser.currentToken() != XContentParser.Token.START_OBJECT) { if (parser.nextToken() != XContentParser.Token.START_OBJECT) { throw new ParsingException(parser.getTokenLocation(), "[_na] query malformed, must start with start_object"); } } if (parser.nextToken() == XContentParser.Token.END_OBJECT) { // we encountered '{}' for a query clause, it used to be supported, deprecated in 5.0 and removed in 6.0 throw new IllegalArgumentException("query malformed, empty clause found at [" + parser.getTokenLocation() +"]"); } if (parser.currentToken() != XContentParser.Token.FIELD_NAME) { throw new ParsingException(parser.getTokenLocation(), "[_na] query malformed, no field after start_object"); } String queryName = parser.currentName(); // move to the next START_OBJECT if (parser.nextToken() != XContentParser.Token.START_OBJECT) { throw new ParsingException(parser.getTokenLocation(), "[" + queryName + "] query malformed, no start_object after query name"); } QueryBuilder result; try { result = parser.namedObject(QueryBuilder.class, queryName, this); } catch (UnknownNamedObjectException e) { // Preserve the error message from 5.0 until we have a compellingly better message so we don't break BWC. // This intentionally doesn't include the causing exception because that'd change the "root_cause" of any unknown query errors throw new ParsingException(new XContentLocation(e.getLineNumber(), e.getColumnNumber()), "no [query] registered for [" + e.getName() + "]"); } //end_object of the specific query (e.g. match, multi_match etc.) element if (parser.currentToken() != XContentParser.Token.END_OBJECT) { throw new ParsingException(parser.getTokenLocation(), "[" + queryName + "] malformed query, expected [END_OBJECT] but found [" + parser.currentToken() + "]"); } //end_object of the query object if (parser.nextToken() != XContentParser.Token.END_OBJECT) { throw new ParsingException(parser.getTokenLocation(), "[" + queryName + "] malformed query, expected [END_OBJECT] but found [" + parser.currentToken() + "]"); } return result; }
public ParsingException(XContentLocation contentLocation, String msg, Throwable cause, Object... args) { super(msg, cause, args); int lineNumber = UNKNOWN_POSITION; int columnNumber = UNKNOWN_POSITION; if (contentLocation != null) { lineNumber = contentLocation.lineNumber; columnNumber = contentLocation.columnNumber; } this.columnNumber = columnNumber; this.lineNumber = lineNumber; }
@Override public XContentLocation getTokenLocation() { JsonLocation loc = parser.getTokenLocation(); if (loc == null) { return null; } return new XContentLocation(loc.getLineNr(), loc.getColumnNr()); }
public void testSearchParseException() throws IOException { SearchContext ctx = new TestSearchContext(null); SearchParseException ex = serialize(new SearchParseException(ctx, "foo", new XContentLocation(66, 666))); assertEquals("foo", ex.getMessage()); assertEquals(66, ex.getLineNumber()); assertEquals(666, ex.getColumnNumber()); assertEquals(ctx.shardTarget(), ex.shard()); }
private static void throwParsingExceptionOnMultipleFields(String queryName, XContentLocation contentLocation, String processedFieldName, String currentFieldName) { if (processedFieldName != null) { throw new ParsingException(contentLocation, "[" + queryName + "] query doesn't support multiple fields, found [" + processedFieldName + "] and [" + currentFieldName + "]"); } }
protected Assertion(XContentLocation location, String field, Object expectedValue) { this.location = location; this.field = field; this.expectedValue = expectedValue; }
@Override public XContentLocation getLocation() { return location; }
public LessThanAssertion(XContentLocation location, String field, Object expectedValue) { super(location, field, expectedValue); }
public GreaterThanAssertion(XContentLocation location, String field, Object expectedValue) { super(location, field, expectedValue); }
public SetSection(XContentLocation location) { this.location = location; }
public LessThanOrEqualToAssertion(XContentLocation location, String field, Object expectedValue) { super(location, field, expectedValue); }
public IsFalseAssertion(XContentLocation location, String field) { super(location, field, false); }
public LengthAssertion(XContentLocation location, String field, Object expectedValue) { super(location, field, expectedValue); }
public IsTrueAssertion(XContentLocation location, String field) { super(location, field, true); }
public DoSection(XContentLocation location) { this.location = location; }
public ClientYamlTestSection(XContentLocation location, String name) { this.location = location; this.name = name; this.executableSections = new ArrayList<>(); }
public XContentLocation getLocation() { return location; }
public static MatchAssertion parse(XContentParser parser) throws IOException { XContentLocation location = parser.getTokenLocation(); Tuple<String,Object> stringObjectTuple = ParserUtils.parseTuple(parser); return new MatchAssertion(location, stringObjectTuple.v1(), stringObjectTuple.v2()); }
public MatchAssertion(XContentLocation location, String field, Object expectedValue) { super(location, field, expectedValue); }
public GreaterThanEqualToAssertion(XContentLocation location, String field, Object expectedValue) { super(location, field, expectedValue); }
public SearchParseException(SearchContext context, String msg, @Nullable XContentLocation location) { this(context, msg, location, null); }
private static void handleMisplacedFunctionsDeclaration(XContentLocation contentLocation, String errorString) { throw new ParsingException(contentLocation, "failed to parse [{}] query. [{}]", NAME, MISPLACED_FUNCTION_MESSAGE_PREFIX + errorString); }
public ParsingException(XContentLocation contentLocation, String msg, Object... args) { this(contentLocation, msg, null, args); }