Skip to content

Commit 7406d4f

Browse files
jtorresfabragithub-actions[bot]
authored andcommitted
Rewrite error messages for At::evaluate
GitOrigin-RevId: b8c05de1f6f2c39104bd47c0814c73506565e79d
1 parent 7e8a0ca commit 7406d4f

File tree

2 files changed

+6
-6
lines changed
  • src/style-spec/expression/definitions
  • test/integration/expression-tests/at/basic

2 files changed

+6
-6
lines changed

src/style-spec/expression/definitions/at.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ class At implements Expression {
3636
const array = (this.input.evaluate(ctx) as Array<Value>);
3737

3838
if (index < 0) {
39-
throw new RuntimeError(`Array index out of bounds: ${index} < 0.`);
39+
throw new RuntimeError(`Array index out of bounds: negative index`);
4040
}
4141

4242
if (index >= array.length) {
43-
throw new RuntimeError(`Array index out of bounds: ${index} > ${array.length - 1}.`);
43+
throw new RuntimeError(`Array index out of bounds: index exceeds array size`);
4444
}
4545

4646
if (index !== Math.floor(index)) {
47-
throw new RuntimeError(`Array index must be an integer, but found ${index} instead. Use at-interpolated to retrieve interpolated result with a fractional index.`);
47+
throw new RuntimeError(`Array index must be an integer. Use at-interpolated for fractional indices`);
4848
}
4949

5050
return array[index];

test/integration/expression-tests/at/basic/test.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
},
1919
"outputs": [
2020
8,
21-
{"error": "Array index out of bounds: -1 < 0."},
22-
{"error": "Array index out of bounds: 4 > 2."},
23-
{"error": "Array index must be an integer, but found 1.5 instead. Use at-interpolated to retrieve interpolated result with a fractional index."}
21+
{"error": "Array index out of bounds: negative index"},
22+
{"error": "Array index out of bounds: index exceeds array size"},
23+
{"error": "Array index must be an integer. Use at-interpolated for fractional indices"}
2424
],
2525
"serialized": [
2626
"number",

0 commit comments

Comments
 (0)