Skip to content

Commit

Permalink
πŸ›‘ Error in showing error
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Apr 5, 2020
1 parent c55d53b commit 10301b0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Pluto"
uuid = "c3e4b0f8-55cb-11ea-2926-15256bba5781"
license = "MIT"
authors = ["Fons van der Plas <[email protected]>", "MikoΕ‚aj Bochenski <[email protected]>"]
version = "0.5.12"
version = "0.5.13"

[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand Down
2 changes: 1 addition & 1 deletion src/notebookserver/FormatOutput.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function format_output(val::Any)::Tuple{String, MIME}
try
Base.invokelatest(repr, mime, val; context = iocontext), mime
catch ex
Base.invokelatest(repr, mime, ex; context = iocontext), mime
"Failed to show value: \n" * sprint(showerror, ex, stacktrace(backtrace())), MIME("text/plain")
end
end
end
Expand Down
24 changes: 18 additions & 6 deletions src/notebookserver/Notebook.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ end

save_notebook(notebook::Notebook) = save_notebook(notebook, notebook.path)

function load_notebook(io, path)
function load_notebook_nobackup(io, path)
firstline = String(readline(io))

if firstline != "### A Pluto.jl notebook ###"
Expand Down Expand Up @@ -149,21 +149,26 @@ function load_notebook(io, path)
Notebook(path, ordered_cells)
end

function load_notebook_nobackup(path::String)
local loaded
open(path, "r") do io
loaded = load_notebook_nobackup(io, path)
end
loaded
end

function load_notebook(path::String)
backupPath = path
while isfile(backupPath)
backupPath = backupPath * ".backup"
end
cp(path, backupPath)

local loaded
open(path, "r") do io
loaded = load_notebook(io, path)
end
loaded = load_notebook_nobackup(path)

save_notebook(loaded)

if only_versions_differ(path, backupPath)
if only_versions_or_lineorder_differ(path, backupPath)
rm(backupPath)
else
@warn "Old Pluto notebook might not have loaded correctly. Backup saved to: " backupPath
Expand All @@ -182,6 +187,13 @@ function move_notebook(notebook::Notebook, newpath::String)
rm(oldpath)
end

"Check if two savefiles are identical, up to their version numbers and a possible line shuffle.
If a notebook has not yet had all of its cells run, we can't deduce the topological cell order."
function only_versions_or_lineorder_differ(pathA::AbstractString, pathB::AbstractString)
Set(readlines(pathA)[3:end]) == Set(readlines(pathB)[3:end])
end

function only_versions_differ(pathA::AbstractString, pathB::AbstractString)
readlines(pathA)[3:end] == readlines(pathB)[3:end]
end
1 change: 1 addition & 0 deletions src/webserver/Dynamic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ responses[:deletecell] = (body, notebook::Notebook, cell::Cell; initiator::Union

filter!(c->c.uuid β‰  to_delete.uuid, notebook.cells)
putnotebookupdates!(notebook, clientupdate_cell_deleted(notebook, to_delete, initiator=initiator))
save_notebook(notebook) # this might be "too late", but it will save the latest version of `notebook` anyways
end
end

Expand Down
28 changes: 22 additions & 6 deletions test/Notebook.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Test
using Pluto
import Pluto: samplenotebook, Notebook ,Cell, load_notebook, save_notebook
import Pluto: samplenotebook, Notebook ,Cell, load_notebook, load_notebook_nobackup, save_notebook, run_reactive!

function notebook_inputs_equal(nbA, nbB)
x = normpath(nbA.path) == normpath(nbB.path)
Expand All @@ -23,28 +23,34 @@ end
notebookA = samplenotebook()
notebookB = Notebook(joinpath(tempdir(), "Γ©πŸ§‘πŸ’›.jl"), [
Cell("z = y"),
Cell("y = 1")
Cell("v = u"),
Cell("y = x"),
Cell("x = w"),
Cell("using Base"),
Cell("t = 1"),
Cell("w = v"),
Cell("u = t"),
])

@testset "I/O" begin
@test let
nb = notebookB
save_notebook(nb)
result = load_notebook(nb.path)
result = load_notebook_nobackup(nb.path)
notebook_inputs_equal(nb, result)
end
end
@testset "Line endings" for nb in [notebookA, notebookB]
file_contents = sprint(save_notebook, nb)

@test let
result = sread(load_notebook, file_contents, nb.path)
result = sread(load_notebook_nobackup, file_contents, nb.path)
notebook_inputs_equal(nb, result)
end

@test let
file_contents_windowsed = replace(file_contents, "\n" => "\r\n")
result_windowsed = sread(load_notebook, file_contents_windowsed, nb.path)
result_windowsed = sread(load_notebook_nobackup, file_contents_windowsed, nb.path)
notebook_inputs_equal(nb, result_windowsed)
end
end
Expand All @@ -55,10 +61,20 @@ end
])
@test let
file_contents = sprint(save_notebook, nb)
result = sread(load_notebook, sprint(save_notebook, nb), nb.path)
result = sread(load_notebook_nobackup, sprint(save_notebook, nb), nb.path)
notebook_inputs_equal(nb, result)
end
end
@testset "Backup" begin
notebookA.path = tempname() * ".jl"
notebookB.path = tempname() * ".jl"
backup_path = notebookB.path * ".backup"
isfile(backup_path) && rm(backup_path)
run_reactive!(notebookB, notebookB.cells)
save_notebook(notebookB)
notebookC = load_notebook(notebookB.path)
@test !isfile(backup_path)
end

# TODO: tests for things mentioned in https://github.com/fonsp/Pluto.jl/issues/9
# TODO: test bad dirs, filenames, permissions
Expand Down

3 comments on commit 10301b0

@fonsp
Copy link
Owner Author

@fonsp fonsp commented on 10301b0 Apr 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/12321

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.13 -m "<description of version>" 10301b00434fa67df26e64126feb41fc8aae59b4
git push origin v0.5.13

@fonsp
Copy link
Owner Author

@fonsp fonsp commented on 10301b0 Apr 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#61

Please sign in to comment.