Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index out of bounds errors should show index and bound #9880

Closed
timotheecour opened this issue Dec 6, 2018 · 5 comments · Fixed by #10610
Closed

index out of bounds errors should show index and bound #9880

timotheecour opened this issue Dec 6, 2018 · 5 comments · Fixed by #10610

Comments

@timotheecour
Copy link
Member

timotheecour commented Dec 6, 2018

index out of bounds errors should show index and bound in error message; it would often save a lot of debugging time

the code needs to be updated in a number of places:

compiler/ccgexprs.nim:878:39:        localError(p.config, x.info, "index out of bounds")
compiler/semfold.nim:492:37:      localError(g.config, n.info, "index out of bounds: " & $n)
compiler/semfold.nim:496:41:    else: localError(g.config, n.info, "index out of bounds: " & $n)
compiler/semfold.nim:504:37:      localError(g.config, n.info, "index out of bounds: " & $n)
compiler/vm.nim:424:26:  errIndexOutOfBounds = "index out of bounds"
lib/core/typeinfo.nim:197:39:      raise newException(IndexError, "index out of bounds")
lib/core/typeinfo.nim:204:39:      raise newException(IndexError, "index out of bounds")
lib/core/typeinfo.nim:214:39:      raise newException(IndexError, "index out of bounds")
lib/core/typeinfo.nim:222:39:      raise newException(IndexError, "index out of bounds")
lib/pure/base64.nim:71:13:    # avoid index out of bounds when lineLen == encoded length
lib/pure/collections/sharedstrings.nim:52:41:  else: raise newException(IndexError, "index out of bounds")
lib/pure/collections/sharedstrings.nim:56:41:  else: raise newException(IndexError, "index out of bounds")
lib/pure/subexes.nim:88:44:  if result >=% a.len: raiseInvalidFormat("index out of bounds: " & $result)
lib/system/chcks.nim:19:25:  sysFatal(IndexError, "index out of bounds")
lib/system/jssys.nim:161:35:  raise newException(IndexError, "index out of bounds")

i suggest using a single routine to generate the error message, eg:

template formatErrorIndexBound(index: int, n: int): string =
  "index out of bounds: index: " & $index &" n: " & $n
timotheecour added a commit to timotheecour/Nim that referenced this issue Dec 7, 2018
timotheecour added a commit to timotheecour/Nim that referenced this issue Dec 7, 2018
timotheecour added a commit to timotheecour/Nim that referenced this issue Dec 9, 2018
timotheecour added a commit to timotheecour/Nim that referenced this issue Dec 10, 2018
Araq added a commit that referenced this issue Dec 11, 2018
refs #9880 show index and bound in lots of `index out of bounds` errors
@timotheecour
Copy link
Member Author

/cc @kaushalmodi now that PR was merged, there are still some remaining cases, eg:
see failing test commented out here: $nimc_D/tests/misc/tinvalidarrayaccess2.nim

see also:

compiler/vm.nim:424:26: errIndexOutOfBounds = "index out of bounds"
lib/core/typeinfo.nim:197:39: raise newException(IndexError, "index out of bounds")
lib/core/typeinfo.nim:204:39: raise newException(IndexError, "index out of bounds")
lib/core/typeinfo.nim:214:39: raise newException(IndexError, "index out of bounds")
lib/core/typeinfo.nim:222:39: raise newException(IndexError, "index out of bounds")
lib/system/chcks.nim:26:25: sysFatal(IndexError, "index out of bounds")
lib/system/jssys.nim:161:35: raise newException(IndexError, "index out of bounds")

@narimiran
Copy link
Member

now that PR was merged, there are still some remaining cases

That PR is really a nice and useful addition to the language! Can you work on those remaining cases?

@timotheecour
Copy link
Member Author

glad some ppl appreciate importance of helpful error messages, I certainly do (by helpful I mean in particular: shows relevant runtime/compiletime context such as variables involved). I'm busy with other PR's at the moment, until then, feel free to tackle some of these :)

@BontaVlad
Copy link

Made a PR here

@Araq
Copy link
Member

Araq commented Feb 9, 2019

This was implemented.

@Araq Araq closed this as completed Feb 9, 2019
timotheecour added a commit to timotheecour/Nim that referenced this issue Feb 9, 2019
timotheecour added a commit to timotheecour/Nim that referenced this issue Feb 9, 2019
timotheecour added a commit to timotheecour/Nim that referenced this issue Feb 9, 2019
Araq pushed a commit that referenced this issue Feb 10, 2019
* 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`
Araq pushed a commit that referenced this issue Feb 18, 2019
* 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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants