use of org.elasticsearch.common.xcontent.XContentLocation in project elasticsearch by elastic.
the class ExecutableSection method parse.
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);
}
}
use of org.elasticsearch.common.xcontent.XContentLocation in project elasticsearch by elastic.
the class GreaterThanAssertion method parse.
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());
}
use of org.elasticsearch.common.xcontent.XContentLocation in project elasticsearch by elastic.
the class LengthAssertion method parse.
public static LengthAssertion parse(XContentParser parser) throws IOException {
XContentLocation location = parser.getTokenLocation();
Tuple<String, Object> stringObjectTuple = ParserUtils.parseTuple(parser);
assert stringObjectTuple.v2() != null;
int value;
if (stringObjectTuple.v2() instanceof Number) {
value = ((Number) stringObjectTuple.v2()).intValue();
} else {
try {
value = Integer.valueOf(stringObjectTuple.v2().toString());
} catch (NumberFormatException e) {
throw new IllegalArgumentException("length is not a valid number", e);
}
}
return new LengthAssertion(location, stringObjectTuple.v1(), value);
}
use of org.elasticsearch.common.xcontent.XContentLocation in project elasticsearch by elastic.
the class ClientYamlTestSectionTests method testAddingDoWithWarningWithSkipButNotWarnings.
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());
}
use of org.elasticsearch.common.xcontent.XContentLocation in project elasticsearch by elastic.
the class QueryParseContext method parseInnerQueryBuilder.
/**
* 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) {
// 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;
}
Aggregations