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

Strange Error when formatting a file #332

Closed
kellertuer opened this issue Nov 19, 2020 · 6 comments · Fixed by #334
Closed

Strange Error when formatting a file #332

kellertuer opened this issue Nov 19, 2020 · 6 comments · Fixed by #334
Labels
bug Something isn't working

Comments

@kellertuer
Copy link

Consider the file here

https://github.com/JuliaManifolds/Manopt.jl/blob/chambolle-pock/examples/ChambollePock/SPD_Signal_TV.jl

running on that file a format yields an error, that I do not understand (see below) but more surprisingly, commenting out line 21, i.e. changing it to

#export_any = export_orig || export_primal || export_table

makes formatter pass even with true, so a correctly formatted file.
Any idea why without commenting out the following error occurs?

Happens on JuliaFormatter v0.10.8 with Julia 1.5.2.

julia> format("examples/ChambollePock/SPD_Signal_TV.jl")
ERROR: MethodError: no method matching iterate(::Nothing)
Closest candidates are:
  iterate(::DataStructures.SparseIntSet, ::Any...) at~/.julia/packages/DataStructures/DLSxi/src/sparse_int_set.jl:147
  iterate(::Base.Iterators.ProductIterator{Tuple{}}) at iterators.jl:959
  iterate(::Base.Iterators.ProductIterator{Tuple{}}, ::Any) at iterators.jl:960
  ...
Stacktrace:
 [1] indexed_iterate(::Nothing, ::Int64) at ./tuple.jl:84
 [2] #p_literal#71 at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:414 [inlined]
 [3] #p_literal#76 at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:475 [inlined]
 [4] p_literal(::BlueStyle, ::CSTParser.EXPR, ::JuliaFormatter.State) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:475
 [5] pretty(::DefaultStyle, ::CSTParser.EXPR, ::JuliaFormatter.State; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:13
 [6] pretty(::DefaultStyle, ::CSTParser.EXPR, ::JuliaFormatter.State) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:3
 [7] pretty(::BlueStyle, ::CSTParser.EXPR, ::JuliaFormatter.State; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:144
 [8] pretty(::BlueStyle, ::CSTParser.EXPR, ::JuliaFormatter.State) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:144
 [9] p_call(::DefaultStyle, ::CSTParser.EXPR, ::JuliaFormatter.State) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:1588
 [10] p_call(::BlueStyle, ::CSTParser.EXPR, ::JuliaFormatter.State) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/blue/pretty.jl:96
 [11] pretty(::DefaultStyle, ::CSTParser.EXPR, ::JuliaFormatter.State; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:71
 [12] pretty(::DefaultStyle, ::CSTParser.EXPR, ::JuliaFormatter.State) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:3
 [13] pretty(::BlueStyle, ::CSTParser.EXPR, ::JuliaFormatter.State; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:144
 [14] pretty(::BlueStyle, ::CSTParser.EXPR, ::JuliaFormatter.State) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:144
 [15] p_binaryopcall(::BlueStyle, ::CSTParser.EXPR, ::JuliaFormatter.State; nonest::Bool, nospace::Bool) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/blue/pretty.jl:181
 [16] p_binaryopcall(::BlueStyle, ::CSTParser.EXPR, ::JuliaFormatter.State) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/blue/pretty.jl:110
 [17] pretty(::DefaultStyle, ::CSTParser.EXPR, ::JuliaFormatter.State; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:83
 [18] pretty(::DefaultStyle, ::CSTParser.EXPR, ::JuliaFormatter.State) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:3
 [19] pretty(::BlueStyle, ::CSTParser.EXPR, ::JuliaFormatter.State; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:144
 [20] pretty(::BlueStyle, ::CSTParser.EXPR, ::JuliaFormatter.State) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:144
 [21] p_fileh(::DefaultStyle, ::CSTParser.EXPR, ::JuliaFormatter.State) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:155
 [22] p_fileh(::BlueStyle, ::CSTParser.EXPR, ::JuliaFormatter.State) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:159
 [23] pretty(::DefaultStyle, ::CSTParser.EXPR, ::JuliaFormatter.State; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:131
 [24] pretty(::DefaultStyle, ::CSTParser.EXPR, ::JuliaFormatter.State) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:3
 [25] pretty(::BlueStyle, ::CSTParser.EXPR, ::JuliaFormatter.State; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:144
 [26] pretty at~/.julia/packages/JuliaFormatter/e1ear/src/styles/default/pretty.jl:144 [inlined]
 [27] format_text(::CSTParser.EXPR, ::BlueStyle, ::JuliaFormatter.State) at~/.julia/packages/JuliaFormatter/e1ear/src/JuliaFormatter.jl:328
 [28] format_text(::String, ::BlueStyle, ::JuliaFormatter.Options) at~/.julia/packages/JuliaFormatter/e1ear/src/JuliaFormatter.jl:324
 [29] #format_text#156 at~/.julia/packages/JuliaFormatter/e1ear/src/JuliaFormatter.jl:316 [inlined]
 [30] format_text at~/.julia/packages/JuliaFormatter/e1ear/src/JuliaFormatter.jl:314 [inlined]
 [31] #format_text#155 at~/.julia/packages/JuliaFormatter/e1ear/src/JuliaFormatter.jl:310 [inlined]
 [32] format_file(::String; overwrite::Bool, verbose::Bool, format_markdown::Bool, format_options::Base.Iterators.Pairs{Symbol,BlueStyle,Tuple{Symbol},NamedTuple{(:style,),Tuple{BlueStyle}}}) at~/.julia/packages/JuliaFormatter/e1ear/src/JuliaFormatter.jl:420
 [33] format(::Tuple{String}; options::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at~/.julia/packages/JuliaFormatter/e1ear/src/JuliaFormatter.jl:529
 [34] format at~/.julia/packages/JuliaFormatter/e1ear/src/JuliaFormatter.jl:505 [inlined]
 [35] #format#165 at~/.julia/packages/JuliaFormatter/e1ear/src/JuliaFormatter.jl:554 [inlined]
 [36] format(::String) at~/.julia/packages/JuliaFormatter/e1ear/src/JuliaFormatter.jl:554
 [37] top-level scope at REPL[2]:1
@domluna domluna added the bug Something isn't working label Nov 19, 2020
@kellertuer
Copy link
Author

Ah i forgot to mention, my .JuliaFormatter.toml just contains style = "blue", maybe that's also related. I will do some more tests tomorrow.

@kellertuer
Copy link
Author

Oh, nice! I found the origin of this. I noticed that another file had a similar line with just one additional variable, so I copied that and in worked.
So I digged a little deeper and checked the line more thoroughly, the character after the last || is not a space but a non-breaking-space (NBSP, U+00A0) in

export_any = export_orig || export_primal || export_table

A few tests (referring to the file above)

  • format_text on that line works
  • format_text on the whole file as a string works
  • putting #= ... =# on all lines before and after that line and running format on that file works
  • putting #= ... =# only on the part after that line and running format works
  • ...

So then I got a little bored and narrowed it down to

format_text("""a = b || c
       f("A")""")

fails (also storing that in a file and running format on that; note that the character before c is a nbsp.

@domluna
Copy link
Owner

domluna commented Nov 21, 2020

What OS are you on I'm unable to reproduce this

@kellertuer
Copy link
Author

Mac OS (Big Sur, so 11),
but if you copy the code from my last comment, that actually does not work, because GitHub seems to heave replaced my sweet nbsp with a space, that's why I explicitly mentioned that again. You have to copy and manually replace the space before c with an nbsp,

@domluna
Copy link
Owner

domluna commented Nov 21, 2020

how do I do that?

@kellertuer
Copy link
Author

Well on Mac OS I have a special characters part in the system, otherwise copy it maybe from here https://www.compart.com/en/unicode/U+00A0

domluna added a commit that referenced this issue Nov 21, 2020
domluna added a commit that referenced this issue Nov 21, 2020
domluna added a commit that referenced this issue Nov 22, 2020
* Count number of bytes in unicode whitespace

fixes #332

* revert change from typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants