summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2019-02-10 13:07:11 -0800
committerAndreas Rumpf <rumpf_a@web.de>2019-02-13 23:30:14 +0100
commit942495611b266bc81dc4374e914fa990f3c2d6a2 (patch)
tree719a4eaa1a1d795a7df110744b282b98ac3db757 /lib/system
parent8f05b3412568ec66a72bcae221613630d561aac0 (diff)
downloadNim-942495611b266bc81dc4374e914fa990f3c2d6a2.tar.gz
revive #10228 (fix #9880) (#10610)
* Make index out of bounds more useful by including the 'bounds'.
* fixes #9880 index out of bounds (remaining cases); revives #10228
* change err msg to: `index 3 not in 0 .. 1`
Diffstat (limited to 'lib/system')
-rw-r--r--lib/system/indexerrors.nim4
-rw-r--r--lib/system/jssys.nim8
2 files changed, 7 insertions, 5 deletions
diff --git a/lib/system/indexerrors.nim b/lib/system/indexerrors.nim
index 8bd69ad71..cb1d522c9 100644
--- a/lib/system/indexerrors.nim
+++ b/lib/system/indexerrors.nim
@@ -1,7 +1,7 @@
 # imported by other modules, unlike helpers.nim which is included
 
 template formatErrorIndexBound*[T](i, a, b: T): string =
-  "index out of bounds: (a: " & $a & ") <= (i: " & $i & ") <= (b: " & $b & ") "
+  "index " & $i & " not in " & $a & " .. " & $b
 
 template formatErrorIndexBound*[T](i, n: T): string =
-  "index out of bounds: (i: " & $i & ") <= (n: " & $n & ") "
+  formatErrorIndexBound(i, 0, n)
diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim
index d7718e4f4..27dd9b020 100644
--- a/lib/system/jssys.nim
+++ b/lib/system/jssys.nim
@@ -7,6 +7,8 @@
 #    distribution, for details about the copyright.
 #
 
+import system/indexerrors
+
 proc log*(s: cstring) {.importc: "console.log", varargs, nodecl.}
 
 type
@@ -157,8 +159,8 @@ proc raiseDivByZero {.exportc: "raiseDivByZero", noreturn, compilerProc.} =
 proc raiseRangeError() {.compilerproc, noreturn.} =
   raise newException(RangeError, "value out of range")
 
-proc raiseIndexError() {.compilerproc, noreturn.} =
-  raise newException(IndexError, "index out of bounds")
+proc raiseIndexError(i, a, b: int) {.compilerproc, noreturn.} =
+  raise newException(IndexError, formatErrorIndexBound(int(i), int(a), int(b)))
 
 proc raiseFieldError(f: string) {.compilerproc, noreturn.} =
   raise newException(FieldError, f & " is not accessible")
@@ -626,7 +628,7 @@ proc arrayConstr(len: int, value: JSRef, typ: PNimType): JSRef {.
 
 proc chckIndx(i, a, b: int): int {.compilerproc.} =
   if i >= a and i <= b: return i
-  else: raiseIndexError()
+  else: raiseIndexError(i, a, b)
 
 proc chckRange(i, a, b: int): int {.compilerproc.} =
   if i >= a and i <= b: return i