org.elasticsearch.search.SearchParseException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch Show documentation
Show all versions of elasticsearch Show documentation
Elasticsearch subproject :distribution:archives:integ-test-zip
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.search;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentLocation;
import java.io.IOException;
public class SearchParseException extends SearchException {
public static final int UNKNOWN_POSITION = -1;
private final int lineNumber;
private final int columnNumber;
public SearchParseException(SearchShardTarget shardTarget, String msg, @Nullable XContentLocation location) {
this(shardTarget, msg, location, null);
}
public SearchParseException(SearchShardTarget shardTarget, String msg, @Nullable XContentLocation location, Throwable cause) {
super(shardTarget, 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;
}
public SearchParseException(StreamInput in) throws IOException {
super(in);
lineNumber = in.readInt();
columnNumber = in.readInt();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeInt(lineNumber);
out.writeInt(columnNumber);
}
@Override
public RestStatus status() {
return RestStatus.BAD_REQUEST;
}
@Override
protected void metadataToXContent(XContentBuilder builder, Params params) throws IOException {
if (lineNumber != UNKNOWN_POSITION) {
builder.field("line", lineNumber);
builder.field("col", columnNumber);
}
}
/**
* Line number of the location of the error
*
* @return the line number or -1 if unknown
*/
public int getLineNumber() {
return lineNumber;
}
/**
* Column number of the location of the error
*
* @return the column number or -1 if unknown
*/
public int getColumnNumber() {
return columnNumber;
}
}