Skip to content

Commit dd34485

Browse files
[query-engine] Tweak slice validation errors (#2721)
Relates to #2636 # Changes * Tweak the slice validation error messages --------- Co-authored-by: Drew Relmas <[email protected]>
1 parent 693b34e commit dd34485

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

rust/experimental/query_engine/engine-recordset/src/scalars/scalar_expressions.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ mod tests {
15421542
),
15431543
ExpressionError::ValidationFailure(
15441544
QueryLocation::new_fake(),
1545-
"Range start for a slice expression cannot be a negative value".into(),
1545+
"Range start for a slice expression cannot be a negative value, encountered '-1' value".into(),
15461546
),
15471547
);
15481548

@@ -1557,7 +1557,7 @@ mod tests {
15571557
),
15581558
ExpressionError::TypeMismatch(
15591559
QueryLocation::new_fake(),
1560-
"Range start for a slice expression should be an integer type".into(),
1560+
"Range start for a slice expression should be an integer type, encountered 'Boolean' type".into(),
15611561
),
15621562
);
15631563

@@ -1572,7 +1572,7 @@ mod tests {
15721572
),
15731573
ExpressionError::ValidationFailure(
15741574
QueryLocation::new_fake(),
1575-
"Range length for a slice expression cannot be a negative value".into(),
1575+
"Range length for a slice expression cannot be a negative value, encountered '-1' value".into(),
15761576
),
15771577
);
15781578

@@ -1587,7 +1587,7 @@ mod tests {
15871587
),
15881588
ExpressionError::TypeMismatch(
15891589
QueryLocation::new_fake(),
1590-
"Range length for a slice expression should be an integer type".into(),
1590+
"Range length for a slice expression should be an integer type, encountered 'Boolean' type".into(),
15911591
),
15921592
);
15931593
}
@@ -1727,7 +1727,7 @@ mod tests {
17271727
),
17281728
ExpressionError::ValidationFailure(
17291729
QueryLocation::new_fake(),
1730-
"String slice index starts at '5' but target ends at index '4'".into(),
1730+
"String slice index starts at '5' but target has a length of '5'".into(),
17311731
),
17321732
);
17331733
}
@@ -1903,7 +1903,7 @@ mod tests {
19031903
),
19041904
ExpressionError::ValidationFailure(
19051905
QueryLocation::new_fake(),
1906-
"Array slice index starts at '5' but target ends at index '4'".into(),
1906+
"Array slice index starts at '5' but target has a length of '5'".into(),
19071907
),
19081908
);
19091909
}

rust/experimental/query_engine/expressions/src/scalars/scalar_expressions.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,14 +1158,19 @@ impl SliceScalarExpression {
11581158
if v < 0 {
11591159
return Err(ExpressionError::ValidationFailure(
11601160
query_location.clone(),
1161-
format!("Range {name} for a slice expression cannot be a negative value"),
1161+
format!(
1162+
"Range {name} for a slice expression cannot be a negative value, encountered '{v}' value"
1163+
),
11621164
));
11631165
}
11641166
Ok(v as usize)
11651167
} else {
11661168
Err(ExpressionError::TypeMismatch(
11671169
query_location.clone(),
1168-
format!("Range {name} for a slice expression should be an integer type"),
1170+
format!(
1171+
"Range {name} for a slice expression should be an integer type, encountered '{}' type",
1172+
value.get_value_type()
1173+
),
11691174
))
11701175
}
11711176
}
@@ -1181,8 +1186,7 @@ impl SliceScalarExpression {
11811186
return Err(ExpressionError::ValidationFailure(
11821187
query_location.clone(),
11831188
format!(
1184-
"{name} slice index starts at '{range_start}' but target ends at index '{}'",
1185-
target_length - 1
1189+
"{name} slice index starts at '{range_start}' but target has a length of '{target_length}'"
11861190
),
11871191
));
11881192
}
@@ -2602,7 +2606,7 @@ mod tests {
26022606
),
26032607
ExpressionError::ValidationFailure(
26042608
QueryLocation::new_fake(),
2605-
"Range start for a slice expression cannot be a negative value".into(),
2609+
"Range start for a slice expression cannot be a negative value, encountered '-1' value".into(),
26062610
),
26072611
);
26082612

@@ -2617,7 +2621,7 @@ mod tests {
26172621
),
26182622
ExpressionError::TypeMismatch(
26192623
QueryLocation::new_fake(),
2620-
"Range start for a slice expression should be an integer type".into(),
2624+
"Range start for a slice expression should be an integer type, encountered 'Boolean' type".into(),
26212625
),
26222626
);
26232627

@@ -2632,7 +2636,7 @@ mod tests {
26322636
),
26332637
ExpressionError::ValidationFailure(
26342638
QueryLocation::new_fake(),
2635-
"Range length for a slice expression cannot be a negative value".into(),
2639+
"Range length for a slice expression cannot be a negative value, encountered '-1' value".into(),
26362640
),
26372641
);
26382642

@@ -2647,7 +2651,7 @@ mod tests {
26472651
),
26482652
ExpressionError::TypeMismatch(
26492653
QueryLocation::new_fake(),
2650-
"Range length for a slice expression should be an integer type".into(),
2654+
"Range length for a slice expression should be an integer type, encountered 'Boolean' type".into(),
26512655
),
26522656
);
26532657
}
@@ -2825,7 +2829,7 @@ mod tests {
28252829
IntegerScalarExpression::new(QueryLocation::new_fake(), 50),
28262830
))),
28272831
),
2828-
"String slice index starts at '50' but target ends at index '4'",
2832+
"String slice index starts at '50' but target has a length of '5'",
28292833
);
28302834

28312835
let large_string_source = ScalarExpression::Static(StaticScalarExpression::String(
@@ -2933,7 +2937,7 @@ mod tests {
29332937
IntegerScalarExpression::new(QueryLocation::new_fake(), 1),
29342938
))),
29352939
),
2936-
"Array slice index starts at '5' but target ends at index '4'",
2940+
"Array slice index starts at '5' but target has a length of '5'",
29372941
);
29382942
}
29392943

0 commit comments

Comments
 (0)