fonsp / Pluto.jl

🎈 Simple reactive notebooks for Julia

Home Page:https://plutojl.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

disberd opened this issue Β· comments

This is a mirror/duplicate of disberd/PlutoDevMacros.jl#30

Since #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:

b7f1726b-4203-4135-905f-f213a6398709.mp4
Notebook Code
### 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

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.