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

Comments

Projects
None yet
4 participants
@timotheecour
Copy link
Contributor

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

Merge pull request #9881 from timotheecour/pr_ref_9880
refs #9880 show index and bound in lots of `index out of bounds` errors
@timotheecour

This comment has been minimized.

Copy link
Contributor Author

commented Dec 11, 2018

/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")

@timotheecour timotheecour added the Easy label Dec 11, 2018

@narimiran

This comment has been minimized.

Copy link
Member

commented Jan 5, 2019

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

This comment has been minimized.

Copy link
Contributor Author

commented Jan 5, 2019

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

This comment has been minimized.

Copy link

commented Jan 7, 2019

Made a PR here

@BontaVlad BontaVlad referenced this issue Jan 7, 2019

Closed

Fixes 9880 #10228

@timotheecour timotheecour removed the Easy label Jan 19, 2019

@Araq

This comment has been minimized.

Copy link
Member

commented Feb 9, 2019

This was implemented.

@Araq Araq closed this 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

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 added a commit that referenced this issue Feb 10, 2019

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`

Araq added a commit that referenced this issue Feb 18, 2019

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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.