fonsp / Pluto.jl

🎈 Simple reactive notebooks for Julia
https://plutojl.org/
MIT License
4.91k stars 284 forks source link

ParseErrors in Julia 1.10 for manually `eval`'d expressions give misleading code location #2819

Closed disberd closed 4 months ago

disberd commented 4 months ago

This is a mirror/duplicate of https://github.com/disberd/PlutoDevMacros.jl/issues/30

Since https://github.com/fonsp/Pluto.jl/pull/2526, on Julia 1.10 Pluto has fancy rendering of ParseErrors.

While this works fine for most of the reasonable use cases, when manually parsing expressions from files and evaluating them with Core.eval (or similar), the error displayed on the cell output has a wrong hyperlink to a non-existing line in the current cell, and it can break codemirror for the cell in question.

Video Example:

https://github.com/fonsp/Pluto.jl/assets/12846528/2c9658a6-bbc4-4ff3-97c2-31e8a48d4e5b

Notebook Code ```julia ### A Pluto.jl notebook ### # v0.19.38 using Markdown using InteractiveUtils # ╔═╡ 7b263142-cf29-11ee-3688-1352da3b20bf fname = tempname() # ╔═╡ b0e94947-7098-4979-947b-01ebcc6aee9c open(fname, "w") do io write(io, """ module ASD a = 1 b = 2 c = 3 """) end # ╔═╡ eda9e79f-a7be-49c9-b451-72af19b30311 macro parse_error(fname) fname = esc(fname) :(let filename = $fname code = read(filename, String) ast = Meta.parseall(code; filename) Core.eval($__module__, ast) end) end # ╔═╡ Cell order: # ╠═7b263142-cf29-11ee-3688-1352da3b20bf # ╠═b0e94947-7098-4979-947b-01ebcc6aee9c # ╠═eda9e79f-a7be-49c9-b451-72af19b30311 ```

Maybe it would be sufficient to do fancy display of ParseErrors only if the source file has the cell UUID at the end of the filename? @Pangoraw

Pangoraw commented 4 months ago

I did not realize parse errors could come from Meta.parse, thank you. With #2820, diagnostics will only come from Pluto parsed expressions and not notebook thrown exceptions.