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

[TODO] [feature] Nim error messages should show line contents, would save lots of debugging time #7586

Closed
2 tasks
timotheecour opened this issue Apr 12, 2018 · 14 comments

Comments

@timotheecour
Copy link
Member

timotheecour commented Apr 12, 2018

  • proposal: add an option --showLineContext:int

this would save tons of debugging time:

with --showLineContext:0 (default value), same as current behavior

/Users/timothee/git_clone/nim/timn/bugs/t15_tuple.nim(47, 17) template/generic instantiation from here
/Users/timothee/.nimble_choosenim/pkgs/tuples-0.1.0/tuples.nim(324, 7) template/generic instantiation from here
/Users/timothee/.nimble_choosenim/pkgs/tuples-0.1.0/tuples.nim(49, 15) template/generic instantiation from here
/Users/timothee/.nimble_choosenim/pkgs/tuples-0.1.0/tuples.nim(74, 16) Error: identifier expected, but found '0'

with --showLineContext:1

/Users/timothee/git_clone/nim/timn/bugs/t15_tuple.nim(47, 17) template/generic instantiation from here:  let a1 = a0 & ("8 / 2", 4).to1Tuple
/Users/timothee/.nimble_choosenim/pkgs/tuples-0.1.0/tuples.nim(324, 7) template/generic instantiation from here:   join((tup0, tup1))
/Users/timothee/.nimble_choosenim/pkgs/tuples-0.1.0/tuples.nim(49, 15) template/generic instantiation from here:     iteration a
/Users/timothee/.nimble_choosenim/pkgs/tuples-0.1.0/tuples.nim(74, 16) Error: identifier expected, but found '0':     iterateFor a, b

possible future extension: --showLineContext:2,3
shows 2 lines above(including self line), 3 lines below (strictly below)

/Users/timothee/git_clone/nim/timn/bugs/t15_tuple.nim(47, 17) template/generic instantiation from here:
  when true:
    let a1 = a0 & ("8 / 2", 4).to1Tuple
  else:
    let a1 = a0
  # when true:
/Users/timothee/.nimble_choosenim/pkgs/tuples-0.1.0/tuples.nim(324, 7) template/generic instantiation from here:
  ## ``join((tup0, tup1))``.
  join((tup0, tup1))

proc zipExpr(outerLen, innerLen: int): PNimrodNode {.compileTime.} =
  result = newPar()
  • with --colorizeLineContext:true we'd also:
  • highlight (say in green) line at context 0 to distinguish from context above/below
  • highlight (say in blue) (with underscore, so it works with spaces too) column mentioned in error message EDIT

EDIT nimgrep's logic can be reused for that purpose

@dom96
Copy link
Contributor

dom96 commented Apr 12, 2018

Pretty sure --verbosity:3 already shows this.

@timotheecour
Copy link
Member Author

timotheecour commented Apr 12, 2018

with --verbosity:3 all i get is 1 line context at the last entry; which is quite different and not as useful. Oftentimes, the relevant information the user is searching for is not in the last entry.

/Users/timothee/git_clone/nim/timn/bugs/t15_tuple.nim(47, 17) template/generic instantiation from here
/Users/timothee/.nimble_choosenim/pkgs/tuples-0.1.0/tuples.nim(324, 7) template/generic instantiation from here
/Users/timothee/.nimble_choosenim/pkgs/tuples-0.1.0/tuples.nim(49, 15) template/generic instantiation from here
/Users/timothee/.nimble_choosenim/pkgs/tuples-0.1.0/tuples.nim(74, 16) Error: identifier expected, but found '0'
      iterateFor a, b
                 ^

Also, it's doing other stuff too; it's good to keep features orthogonal

@alehander92
Copy link
Contributor

I have to agree, I even think it's very useful to file context visible by default: would that somehow break anything depending on the output?

@alehander92
Copy link
Contributor

alehander92 commented Apr 13, 2018

verbosity:3 shows one line indeed, and it also shows too much stuff one usually doesn't need

@Araq
Copy link
Member

Araq commented Apr 13, 2018

----hint[source]:on is the switch to get this. Somebody needs to make it the default and/or document it.

@Araq Araq added Documentation Content Related to documentation content (not generation). Easy labels Apr 13, 2018
@timotheecour
Copy link
Member Author

timotheecour commented Apr 16, 2018

@Araq
I added hint[Source]:on to nim.cfg and it still shows error messages without line contents, eg:

nim c -o:app -r bugs/t20_jester_type_mismatch.nim
Hint: used config file '/Users/timothee/.choosenim/toolchains/nim-#devel/config/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/.config/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/git_clone/nim/timn/nim.cfg' [Conf]
/Users/timothee/.nimble_choosenim/pkgs/jester-0.2.0/jester.nim(531, 21) Error: type mismatch: got <Time> but expected 'int'

(note: as for the error itself, i just filed dom96/jester#138)

also tried with: ----hint[source]:on or hint[source]:on

I would expect to see line contents instead, eg smthg like:

/Users/timothee/.nimble_choosenim/pkgs/jester-0.2.0/jester.nim(531, 21) Error: type mismatch: got <Time> but expected 'int': var tim = Time(int(getTime()) + days * (60 * 60 * 24))

@Araq
Copy link
Member

Araq commented Apr 16, 2018

@timotheecour, strange, I tested it from command line and it worked just fine. It's also enabled with --verbosity:2 fwiw.

@timotheecour
Copy link
Member Author

timotheecour commented Apr 16, 2018

NOTE: also, it's verbosity:2 or 3, not 3.

EDIT

It's also enabled with --verbosity:2 fwiw.

lol, hadn't seen your comment above, posted that at same time...
however still doesn't work with '--hint[Source]:on' unless i add --verbosity:2 or hack proc liMessage in msgs.nim ;

@timotheecour
Copy link
Member Author

timotheecour commented Apr 16, 2018

  • not sure why it works for you but not in my setup; in any case even with --verbosity:2 it just prints last context, not all contexts
  • a (partial) fix seems easy, with this patch it always prints context, so I just need to make it depend on hintSource or another cmd line param:
      # if msg in errMin..errMax and hintSource in gNotes:
      #   info.writeSurroundingSrc
      info.writeSurroundingSrc
  • when color mode is enabled, using underline instead of a caret below would save 1 line
  • not sure if it adds non-negligible processing time, if it does, it shd stay as a non-default option

i could try a PR tmrw

timotheecour added a commit to timotheecour/Nim that referenced this issue Apr 16, 2018
hintsSourceError to print context for errors (ie last entry if
compilation aborts on error); adjust these hints in verbosity; minor
code clarification
@timotheecour
Copy link
Member Author

=> #7635

timotheecour added a commit to timotheecour/Nim that referenced this issue Apr 17, 2018
hintsSourceError to print context for errors (ie last entry if
compilation aborts on error); adjust these hints in verbosity; minor
code clarification
@CodeDoes
Copy link

this should be closed

@Araq Araq reopened this Apr 28, 2018
@Araq
Copy link
Member

Araq commented Apr 28, 2018

I marked it with "documentation". The documentation has not been improved.

@drslump
Copy link
Contributor

drslump commented Aug 13, 2018

I had a go at documenting the hints #8625

dom96 added a commit that referenced this issue Aug 14, 2018
@timotheecour timotheecour changed the title [feature] Nim error messages should show line contents, would save lots of debugging time [TODO] [feature] Nim error messages should show line contents, would save lots of debugging time Aug 14, 2018
@timotheecour
Copy link
Member Author

timotheecour commented Sep 11, 2018

/cc @dom96 could we reopen? the problem is still there:

proc foo2[]()=
  var foo2: int = 3.0
proc foo1[]()=
  foo2()
proc main()=
  foo1()

main()

nim c --hint:source:on issue_7586.nim

issue_7586.nim(5, 1) template/generic instantiation from here
issue_7586.nim(6, 7) template/generic instantiation from here
issue_7586.nim(4, 7) template/generic instantiation from here
issue_7586.nim(2, 19) Error: type mismatch: got <float64> but expected 'int'
    var foo2: int = 3.0
                    ^

instead of:

issue_7586.nim(7, 1) template/generic instantiation from here
    proc main()=
issue_7586.nim(8, 7) template/generic instantiation from here
    foo1()
issue_7586.nim(6, 7) template/generic instantiation from here
    foo2()
issue_7586.nim(4, 19) Error: type mismatch: got <float64> but expected 'int'
    var foo2: int = 3.0
                    ^

it doesn't have to be the default with --hint:source:on, it could be via --hint:sourceAll:on if needed, there needs to be a flag for that

@timotheecour timotheecour added Error Messages and removed Documentation Content Related to documentation content (not generation). labels Jan 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants