JuliaInterop / NBInclude.jl

import code from IJulia Jupyter notebooks into Julia programs
Other
117 stars 17 forks source link

HELP! `nbexport`: using input arguments in incorrect order completely deletes/empties the Notebook #30

Closed Datseris closed 3 months ago

Datseris commented 3 months ago

help help help help

I just called nbexport("file.ipynb", "file.jl"). I put in the arguments in the incorrect order: the Julia file should be first.

Now my Jupyter notebook is completely empty it has nothing, and has already been saved. There is no Julia file of course.

help help help is this possible to reverse? I can't find the notebook anywhere because I don't commit notebooks to git.

Datseris commented 3 months ago

The full error was:

ERROR: SystemError: opening file "c:\\Users\\gd419\\OneDrive - University of Exeter\\Projects\\ComplexityMeasuresPaper\\notebooks\\measure_count.jl": No such 
file or directory
Stacktrace:
  [1] systemerror(p::String, errno::Int32; extrainfo::Nothing)
    @ Base .\error.jl:176
  [2] systemerror
    @ Base .\error.jl:175 [inlined]
  [3] open(fname::String; lock::Bool, read::Bool, write::Nothing, create::Nothing, truncate::Nothing, append::Nothing)
    @ Base .\iostream.jl:293
  [4] open
    @ Base .\iostream.jl:275 [inlined]
  [5] open(fname::String, mode::String; lock::Bool)
    @ Base .\iostream.jl:356
  [6] open(fname::String, mode::String)
    @ Base .\iostream.jl:355
  [7] open(::typeof(JSON.Parser.parse), ::String, ::Vararg{String}; kwargs::@Kwargs{})
    @ Base .\io.jl:394
  [8] open
    @ .\io.jl:393 [inlined]
  [9] nbexport(io::IOStream, nbpath::String; regex::Regex, markdown::Bool)     
    @ NBInclude C:\Users\gd419\.julia\packages\NBInclude\MxvbF\src\NBInclude.jl:172
 [10] nbexport
    @ C:\Users\gd419\.julia\packages\NBInclude\MxvbF\src\NBInclude.jl:171 [inlined]
 [11] #7
    @ C:\Users\gd419\.julia\packages\NBInclude\MxvbF\src\NBInclude.jl:192 [inlined]
 [12] open(::NBInclude.var"#7#8"{@Kwargs{}, String}, ::String, ::Vararg{String}; kwargs::@Kwargs{})
    @ Base .\io.jl:396
 [13] open
    @ Base .\io.jl:393 [inlined]
 [14] #nbexport#6
    @ NBInclude C:\Users\gd419\.julia\packages\NBInclude\MxvbF\src\NBInclude.jl:192 [inlined]
 [15] nbexport(jlpath::String, nbpath::String)
    @ NBInclude C:\Users\gd419\.julia\packages\NBInclude\MxvbF\src\NBInclude.jl:191
 [16] top-level scope
    @ REPL[7]:1
Datseris commented 3 months ago

this happened while the notebook was open in VSCode, Windows 10.

stevengj commented 3 months ago

Nothing we can do on our end. You could try to use a file recovery tool in your operating system.

Datseris commented 3 months ago

Right, this was closed, but was the issue fixed? Calling the function from this package deleted my file, sounds like a bug to me. Shouldn't there at least be an error message if the arguments are given in the opposite order?

stevengj commented 3 months ago

Calling open("foo", "w") will also delete your file — in general we can't protect from this. It's not a bug — programming languages provide few or no protections against overwriting files, unlike GUI interfaces.

However, we can probably fix it to throw an error before writing the output if the notebook file is broken, which would be a bit friendlier.

Datseris commented 3 months ago

thank you!