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

Location missing on literal syntax errors #2322

Closed
1 task done
yuhan0 opened this issue May 14, 2024 · 4 comments · Fixed by #2333
Closed
1 task done

Location missing on literal syntax errors #2322

yuhan0 opened this issue May 14, 2024 · 4 comments · Fixed by #2333
Projects

Comments

@yuhan0
Copy link
Contributor

yuhan0 commented May 14, 2024

  • I have read the Clojure etiquette and will respect it when communicating on this platform.

version

clj-kondo v2024.03.13

platform

native

editor

NA

problem

The following syntax errors cause clj-kondo to report an null / incorrect error location and interfere with the reporting of all other linting errors in the file. (this makes it trickier than usual to pinpoint the source of the error)

repro

$ echo '\u12345' | clj-kondo --lint -
<stdin>::: error: Invalid unicode literal: \u12345.
linting took 41ms, errors: 1, warnings: 0

$ echo '\o8' | clj-kondo --lint -
<stdin>::: error: Invalid digit 8 in unicode character \o8.
linting took 66ms, errors: 1, warnings: 0

Note the missing line and column locations (this confuses the Emacs flycheck checker)
Also \o denotes an octal, not unicode escape.

$ echo '##' | clj-kondo --lint -
<stdin>:1:3: error: EOF while reading.
linting took 47ms, errors: 1, warnings: 0

$ echo '99r0' | clj-kondo --lint -
<stdin>:1:: error: Radix out of range
linting took 32ms, errors: 1, warnings: 0

$ echo "oops\n\n2r123" | clj-kondo --lint -
<stdin>:1:: error: For input string: "123"
linting took 73ms, errors: 1, warnings: 0

In these cases the line number 1 is reported regardless of where the error occurs, and other lint warnings (eg. unresolved symbol) before or after the parsing errors are not reported.
Note too the incomplete error message in the last line.

config
NA

expected behavior

clj-kondo should report the line/column location of these syntax errors, similar to what it does in other similar situations:

$ echo "oops\n1.0/3\n\\spcae" | clj-kondo --lint -
<stdin>:1:1: error: Unresolved symbol: oops
<stdin>:2:1: error: Invalid number: 1.0/3.
<stdin>:3:1: error: Unsupported character: spcae.
linting took 71ms, errors: 3, warnings: 0
@borkdude borkdude added this to Needs triage in clj-kondo via automation May 14, 2024
@borkdude borkdude moved this from Needs triage to High priority (next release) in clj-kondo May 14, 2024
@borkdude
Copy link
Member

thanks

@yuhan0
Copy link
Contributor Author

yuhan0 commented May 14, 2024

Here they are formatted for easier copying :)

#: #:: ##InF ## ;; invalid tokens

\u0 \u123x \u12345 \udfff ;; invalid unicode escapes

\o789  ;; invalid octal escape

1r0 37r0 ;; radix out of range (2-36)

2r012 16raaah ;; digit out of radix range

@borkdude borkdude moved this from High priority (next release) to In progress in clj-kondo May 17, 2024
clj-kondo automation moved this from In progress to Done May 17, 2024
@yuhan0
Copy link
Contributor Author

yuhan0 commented May 26, 2024

Thanks for the fix!
On the latest version the unicode and octal characters now report the error location, however the invalid numbers and symbolic dispatches are still broken.

Thanks to the above commit I was able to poke around the source and found that the ## token throws a reader error with {:ex-kind :eof} ex-data.

Adding another (= ex-kind :eof) clause here solves it:


But a less brittle solution might be to simply remove the or expression and surface all reader exceptions? Instead of (in the else branch) throwing them to downstream handlers, which ultimately results in the location info being lost.

@borkdude
Copy link
Member

Feel free to poke around and provide a PR with any improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
clj-kondo
  
Done
Development

Successfully merging a pull request may close this issue.

2 participants