Skip to content

Commit 2c44f91

Browse files
authored
[8.12] ESQL: Update the use of some user-caused exceptions (#104046) (#104097)
* ESQL: Update the use of some user-caused exceptions (#104046) This updates the use of the exceptions subclassed from `QlServerException` when the failure reason is user-caused. This ensures that a 400-class response is returned, instead of a 500-class one. * Redd import dropped by merge
1 parent 21df699 commit 2c44f91

File tree

18 files changed

+105
-48
lines changed

18 files changed

+105
-48
lines changed

docs/changelog/104046.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 104046
2+
summary: "ESQL: Update the use of some user-caused exceptions"
3+
area: ES|QL
4+
type: bug
5+
issues: []

docs/reference/esql/functions/to_integer.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ provide information on the source of the failure:
2626

2727
A following header will contain the failure reason and the offending value:
2828

29-
`"org.elasticsearch.xpack.ql.QlIllegalArgumentException: [501379200000] out of [integer] range"`
29+
`"org.elasticsearch.xpack.ql.InvalidArgumentException: [501379200000] out of [integer] range"`
3030

3131

3232
If the input parameter is of a date type, its value will be interpreted as

x-pack/plugin/esql/src/main/java/generated/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToLongFromDoubleEvaluator.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.elasticsearch.compute.operator.DriverContext;
1515
import org.elasticsearch.compute.operator.EvalOperator;
1616
import org.elasticsearch.xpack.ql.InvalidArgumentException;
17-
import org.elasticsearch.xpack.ql.QlIllegalArgumentException;
1817
import org.elasticsearch.xpack.ql.tree.Source;
1918

2019
/**
@@ -39,7 +38,7 @@ public Block evalVector(Vector v) {
3938
if (vector.isConstant()) {
4039
try {
4140
return driverContext.blockFactory().newConstantLongBlockWith(evalValue(vector, 0), positionCount);
42-
} catch (InvalidArgumentException | QlIllegalArgumentException e) {
41+
} catch (InvalidArgumentException e) {
4342
registerException(e);
4443
return driverContext.blockFactory().newConstantNullBlock(positionCount);
4544
}
@@ -48,7 +47,7 @@ public Block evalVector(Vector v) {
4847
for (int p = 0; p < positionCount; p++) {
4948
try {
5049
builder.appendLong(evalValue(vector, p));
51-
} catch (InvalidArgumentException | QlIllegalArgumentException e) {
50+
} catch (InvalidArgumentException e) {
5251
registerException(e);
5352
builder.appendNull();
5453
}
@@ -82,7 +81,7 @@ public Block evalBlock(Block b) {
8281
}
8382
builder.appendLong(value);
8483
valuesAppended = true;
85-
} catch (InvalidArgumentException | QlIllegalArgumentException e) {
84+
} catch (InvalidArgumentException e) {
8685
registerException(e);
8786
}
8887
}

x-pack/plugin/esql/src/main/java/generated/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToLongFromUnsignedLongEvaluator.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.elasticsearch.compute.operator.DriverContext;
1414
import org.elasticsearch.compute.operator.EvalOperator;
1515
import org.elasticsearch.xpack.ql.InvalidArgumentException;
16-
import org.elasticsearch.xpack.ql.QlIllegalArgumentException;
1716
import org.elasticsearch.xpack.ql.tree.Source;
1817

1918
/**
@@ -38,7 +37,7 @@ public Block evalVector(Vector v) {
3837
if (vector.isConstant()) {
3938
try {
4039
return driverContext.blockFactory().newConstantLongBlockWith(evalValue(vector, 0), positionCount);
41-
} catch (InvalidArgumentException | QlIllegalArgumentException e) {
40+
} catch (InvalidArgumentException e) {
4241
registerException(e);
4342
return driverContext.blockFactory().newConstantNullBlock(positionCount);
4443
}
@@ -47,7 +46,7 @@ public Block evalVector(Vector v) {
4746
for (int p = 0; p < positionCount; p++) {
4847
try {
4948
builder.appendLong(evalValue(vector, p));
50-
} catch (InvalidArgumentException | QlIllegalArgumentException e) {
49+
} catch (InvalidArgumentException e) {
5150
registerException(e);
5251
builder.appendNull();
5352
}
@@ -81,7 +80,7 @@ public Block evalBlock(Block b) {
8180
}
8281
builder.appendLong(value);
8382
valuesAppended = true;
84-
} catch (InvalidArgumentException | QlIllegalArgumentException e) {
83+
} catch (InvalidArgumentException e) {
8584
registerException(e);
8685
}
8786
}

x-pack/plugin/esql/src/main/java/generated/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToUnsignedLongFromDoubleEvaluator.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.elasticsearch.compute.operator.DriverContext;
1515
import org.elasticsearch.compute.operator.EvalOperator;
1616
import org.elasticsearch.xpack.ql.InvalidArgumentException;
17-
import org.elasticsearch.xpack.ql.QlIllegalArgumentException;
1817
import org.elasticsearch.xpack.ql.tree.Source;
1918

2019
/**
@@ -39,7 +38,7 @@ public Block evalVector(Vector v) {
3938
if (vector.isConstant()) {
4039
try {
4140
return driverContext.blockFactory().newConstantLongBlockWith(evalValue(vector, 0), positionCount);
42-
} catch (InvalidArgumentException | QlIllegalArgumentException e) {
41+
} catch (InvalidArgumentException e) {
4342
registerException(e);
4443
return driverContext.blockFactory().newConstantNullBlock(positionCount);
4544
}
@@ -48,7 +47,7 @@ public Block evalVector(Vector v) {
4847
for (int p = 0; p < positionCount; p++) {
4948
try {
5049
builder.appendLong(evalValue(vector, p));
51-
} catch (InvalidArgumentException | QlIllegalArgumentException e) {
50+
} catch (InvalidArgumentException e) {
5251
registerException(e);
5352
builder.appendNull();
5453
}
@@ -82,7 +81,7 @@ public Block evalBlock(Block b) {
8281
}
8382
builder.appendLong(value);
8483
valuesAppended = true;
85-
} catch (InvalidArgumentException | QlIllegalArgumentException e) {
84+
} catch (InvalidArgumentException e) {
8685
registerException(e);
8786
}
8887
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToLong.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
1313
import org.elasticsearch.xpack.esql.expression.function.Param;
1414
import org.elasticsearch.xpack.ql.InvalidArgumentException;
15-
import org.elasticsearch.xpack.ql.QlIllegalArgumentException;
1615
import org.elasticsearch.xpack.ql.expression.Expression;
1716
import org.elasticsearch.xpack.ql.tree.NodeInfo;
1817
import org.elasticsearch.xpack.ql.tree.Source;
@@ -100,12 +99,12 @@ static long fromKeyword(BytesRef in) {
10099
}
101100
}
102101

103-
@ConvertEvaluator(extraName = "FromDouble", warnExceptions = { InvalidArgumentException.class, QlIllegalArgumentException.class })
102+
@ConvertEvaluator(extraName = "FromDouble", warnExceptions = { InvalidArgumentException.class })
104103
static long fromDouble(double dbl) {
105104
return safeDoubleToLong(dbl);
106105
}
107106

108-
@ConvertEvaluator(extraName = "FromUnsignedLong", warnExceptions = { InvalidArgumentException.class, QlIllegalArgumentException.class })
107+
@ConvertEvaluator(extraName = "FromUnsignedLong", warnExceptions = { InvalidArgumentException.class })
109108
static long fromUnsignedLong(long ul) {
110109
return safeToLong(unsignedLongAsNumber(ul));
111110
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToUnsignedLong.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
1313
import org.elasticsearch.xpack.esql.expression.function.Param;
1414
import org.elasticsearch.xpack.ql.InvalidArgumentException;
15-
import org.elasticsearch.xpack.ql.QlIllegalArgumentException;
1615
import org.elasticsearch.xpack.ql.expression.Expression;
1716
import org.elasticsearch.xpack.ql.tree.NodeInfo;
1817
import org.elasticsearch.xpack.ql.tree.Source;
@@ -86,7 +85,7 @@ static long fromKeyword(BytesRef in) {
8685
return asLongUnsigned(safeToUnsignedLong(asString));
8786
}
8887

89-
@ConvertEvaluator(extraName = "FromDouble", warnExceptions = { InvalidArgumentException.class, QlIllegalArgumentException.class })
88+
@ConvertEvaluator(extraName = "FromDouble", warnExceptions = { InvalidArgumentException.class })
9089
static long fromDouble(double dbl) {
9190
return asLongUnsigned(safeToUnsignedLong(dbl));
9291
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateExtract.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import org.elasticsearch.compute.ann.Evaluator;
1313
import org.elasticsearch.compute.ann.Fixed;
1414
import org.elasticsearch.compute.operator.EvalOperator.ExpressionEvaluator;
15-
import org.elasticsearch.xpack.esql.EsqlIllegalArgumentException;
1615
import org.elasticsearch.xpack.esql.evaluator.mapper.EvaluatorMapper;
16+
import org.elasticsearch.xpack.ql.InvalidArgumentException;
1717
import org.elasticsearch.xpack.ql.expression.Expression;
1818
import org.elasticsearch.xpack.ql.expression.TypeResolutions;
1919
import org.elasticsearch.xpack.ql.expression.function.scalar.ConfigurationFunction;
@@ -49,7 +49,7 @@ public ExpressionEvaluator.Factory toEvaluator(Function<Expression, ExpressionEv
4949
ChronoField chrono = chronoField();
5050
if (chrono == null) {
5151
BytesRef field = (BytesRef) children().get(0).fold();
52-
throw new EsqlIllegalArgumentException("invalid date field for [{}]: {}", sourceText(), field.utf8ToString());
52+
throw new InvalidArgumentException("invalid date field for [{}]: {}", sourceText(), field.utf8ToString());
5353
}
5454
return new DateExtractConstantEvaluator.Factory(source(), fieldEvaluator, chrono, configuration().zoneId());
5555
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateParse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
import org.elasticsearch.compute.ann.Evaluator;
1313
import org.elasticsearch.compute.ann.Fixed;
1414
import org.elasticsearch.compute.operator.EvalOperator.ExpressionEvaluator;
15-
import org.elasticsearch.xpack.esql.EsqlIllegalArgumentException;
1615
import org.elasticsearch.xpack.esql.evaluator.mapper.EvaluatorMapper;
1716
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
1817
import org.elasticsearch.xpack.esql.expression.function.Param;
18+
import org.elasticsearch.xpack.ql.InvalidArgumentException;
1919
import org.elasticsearch.xpack.ql.expression.Expression;
2020
import org.elasticsearch.xpack.ql.expression.function.OptionalArgument;
2121
import org.elasticsearch.xpack.ql.expression.function.scalar.ScalarFunction;
@@ -114,7 +114,7 @@ public ExpressionEvaluator.Factory toEvaluator(Function<Expression, ExpressionEv
114114
DateFormatter formatter = toFormatter(format.fold(), zone);
115115
return new DateParseConstantEvaluator.Factory(source(), fieldEvaluator, formatter);
116116
} catch (IllegalArgumentException e) {
117-
throw new EsqlIllegalArgumentException(e, "invalid date pattern for [{}]: {}", sourceText(), e.getMessage());
117+
throw new InvalidArgumentException(e, "invalid date pattern for [{}]: {}", sourceText(), e.getMessage());
118118
}
119119
}
120120
ExpressionEvaluator.Factory formatEvaluator = toEvaluator.apply(format);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/Cast.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.elasticsearch.compute.operator.EvalOperator;
1212
import org.elasticsearch.compute.operator.EvalOperator.ExpressionEvaluator;
1313
import org.elasticsearch.xpack.esql.EsqlIllegalArgumentException;
14-
import org.elasticsearch.xpack.ql.QlIllegalArgumentException;
14+
import org.elasticsearch.xpack.ql.InvalidArgumentException;
1515
import org.elasticsearch.xpack.ql.tree.Source;
1616
import org.elasticsearch.xpack.ql.type.DataType;
1717
import org.elasticsearch.xpack.ql.type.DataTypes;
@@ -88,9 +88,10 @@ static long castIntToUnsignedLong(int v) {
8888
}
8989

9090
@Evaluator(extraName = "LongToUnsignedLong")
91+
// TODO: catch-to-null in evaluator?
9192
static long castLongToUnsignedLong(long v) {
9293
if (v < 0) {
93-
throw new QlIllegalArgumentException("[" + v + "] out of [unsigned_long] range");
94+
throw new InvalidArgumentException("[" + v + "] out of [unsigned_long] range");
9495
}
9596
return v;
9697
}

0 commit comments

Comments
 (0)