FileIO.jl
FileIO.jl copied to clipboard
Confusing error when saving the wrong thing
julia> using CairoMakie
julia> fig = lines(rand(10));
julia> save("test.png", fig) # works
CairoScreen{Cairo.CairoSurfaceBase{UInt32}} with surface:
Cairo.CairoSurfaceBase{UInt32}(Ptr{Nothing} @0x00007fef60cecfa0, 800.0, 600.0)
julia> save("test.png", (fig, )) # wrong argument gives confusing errors
Errors encountered while save FileIO.File{FileIO.DataFormat{:PNG}, String}("test.png").
All errors:
===========================================
ImageIO writer error: neither save nor fileio_save is defined
due to MethodError(ImageIO.save, (FileIO.File{FileIO.DataFormat{:PNG}, String}("test.png"), (Scene (800px, 600px):
18 Plots:
├ Combined{Makie.poly, Tuple{Vector{Vector{Point{2, Float32}}}}}
├ LineSegments{Tuple{Vector{Point{2, Float32}}}}
├ LineSegments{Tuple{Vector{Point{2, Float32}}}}
├ LineSegments{Tuple{Vector{Point{2, Float32}}}}
├ LineSegments{Tuple{Vector{Point{2, Float32}}}}
├ LineSegments{Tuple{Vector{Point{2, Float32}}}}
├ LineSegments{Tuple{Vector{Point{2, Float32}}}}
├ MakieCore.Text{Tuple{String}}
├ Lines{Tuple{Vector{Point{2, Float32}}}}
├ MakieCore.Text{Tuple{Vector{Tuple{AbstractString, Point{2, Float32}}}}}
├ LineSegments{Tuple{Vector{Point{2, Float32}}}}
├ LineSegments{Tuple{Vector{Point{2, Float32}}}}
├ MakieCore.Text{Tuple{String}}
├ Lines{Tuple{Vector{Point{2, Float32}}}}
├ MakieCore.Text{Tuple{Vector{Tuple{AbstractString, Point{2, Float32}}}}}
├ Lines{Tuple{Vector{Point{2, Float32}}}}
├ Lines{Tuple{Vector{Point{2, Float32}}}}
└ MakieCore.Text{Tuple{String}}
1 Child Scene:
└ Scene (724px, 541px),)), 0x0000000000007aad)
Will try next loader.
===========================================
ArgumentError: Package QuartzImageIO [dca85d43-d64c-5e67-8c65-017450d5d020] is required but does not seem to be installed:
- Run `Pkg.instantiate()` to install all recorded dependencies.
===========================================
ArgumentError: Package ImageMagick [6218d12a-5da1-5696-b52f-db25d2ecc6d1] is required but does not seem to be installed:
- Run `Pkg.instantiate()` to install all recorded dependencies.
===========================================
ArgumentError: Argument does not support conversion to png.
===========================================
Fatal error:
ERROR: ImageIO writer error: neither save nor fileio_save is defined
due to MethodError(ImageIO.save, (FileIO.File{FileIO.DataFormat{:PNG}, String}("test.png"), (Scene (800px, 600px):
18 Plots:
├ Combined{Makie.poly, Tuple{Vector{Vector{Point{2, Float32}}}}}
├ LineSegments{Tuple{Vector{Point{2, Float32}}}}
├ LineSegments{Tuple{Vector{Point{2, Float32}}}}
├ LineSegments{Tuple{Vector{Point{2, Float32}}}}
├ LineSegments{Tuple{Vector{Point{2, Float32}}}}
├ LineSegments{Tuple{Vector{Point{2, Float32}}}}
├ LineSegments{Tuple{Vector{Point{2, Float32}}}}
├ MakieCore.Text{Tuple{String}}
├ Lines{Tuple{Vector{Point{2, Float32}}}}
├ MakieCore.Text{Tuple{Vector{Tuple{AbstractString, Point{2, Float32}}}}}
├ LineSegments{Tuple{Vector{Point{2, Float32}}}}
├ LineSegments{Tuple{Vector{Point{2, Float32}}}}
├ MakieCore.Text{Tuple{String}}
├ Lines{Tuple{Vector{Point{2, Float32}}}}
├ MakieCore.Text{Tuple{Vector{Tuple{AbstractString, Point{2, Float32}}}}}
├ Lines{Tuple{Vector{Point{2, Float32}}}}
├ Lines{Tuple{Vector{Point{2, Float32}}}}
└ MakieCore.Text{Tuple{String}}
1 Child Scene:
└ Scene (724px, 541px),)), 0x0000000000007aad)
Will try next loader.
Stacktrace:
[1] #invokelatest#2
@ ./essentials.jl:716 [inlined]
[2] invokelatest
@ ./essentials.jl:714 [inlined]
[3] action(call::Symbol, libraries::Vector{Union{Base.PkgId, Module}}, file::FileIO.Formatted, args::Tuple{Makie.FigureAxisPlot}; options::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ FileIO ~/.julia/packages/FileIO/JA3Vl/src/loadsave.jl:217
[4] action
@ ~/.julia/packages/FileIO/JA3Vl/src/loadsave.jl:197 [inlined]
[5] action(call::Symbol, libraries::Vector{Union{Base.PkgId, Module}}, sym::Symbol, file::String, args::Tuple{Makie.FigureAxisPlot}; options::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ FileIO ~/.julia/packages/FileIO/JA3Vl/src/loadsave.jl:185
[6] action
@ ~/.julia/packages/FileIO/JA3Vl/src/loadsave.jl:185 [inlined]
[7] #save#20
@ ~/.julia/packages/FileIO/JA3Vl/src/loadsave.jl:129 [inlined]
[8] save(file::String, args::Tuple{Makie.FigureAxisPlot})
@ FileIO ~/.julia/packages/FileIO/JA3Vl/src/loadsave.jl:126
[9] top-level scope
@ REPL[23]:1
[10] eval
@ ./boot.jl:373 [inlined]
[11] eval_user_input(ast::Any, backend::REPL.REPLBackend)
@ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:150
[12] repl_backend_loop(backend::REPL.REPLBackend)
@ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:241
[13] start_repl_backend(backend::REPL.REPLBackend, consumer::Any)
@ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:226
[14] run_repl(repl::REPL.AbstractREPL, consumer::Any; backend_on_current_task::Bool)
@ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:359
[15] run_repl(repl::REPL.AbstractREPL, consumer::Any)
@ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:346
[16] (::Base.var"#919#921"{Bool, Bool, Bool})(REPL::Module)
@ Base ./client.jl:394
[17] #invokelatest#2
@ ./essentials.jl:716 [inlined]
[18] invokelatest
@ ./essentials.jl:714 [inlined]
[19] run_main_repl(interactive::Bool, quiet::Bool, banner::Bool, history_file::Bool, color_set::Bool)
@ Base ./client.jl:379
[20] exec_options(opts::Base.JLOptions)
@ Base ./client.jl:309
[21] _start()
@ Base ./client.jl:495
Stacktrace:
[1] handle_error(e::FileIO.WriterError, q::Base.PkgId, bt::Vector{Union{Ptr{Nothing}, Base.InterpreterIP}})
@ FileIO ~/.julia/packages/FileIO/JA3Vl/src/error_handling.jl:61
[2] handle_exceptions(exceptions::Vector{Tuple{Any, Union{Base.PkgId, Module}, Vector}}, action::String)
@ FileIO ~/.julia/packages/FileIO/JA3Vl/src/error_handling.jl:56
[3] action(call::Symbol, libraries::Vector{Union{Base.PkgId, Module}}, file::FileIO.Formatted, args::Tuple{Makie.FigureAxisPlot}; options::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ FileIO ~/.julia/packages/FileIO/JA3Vl/src/loadsave.jl:226
[4] action
@ ~/.julia/packages/FileIO/JA3Vl/src/loadsave.jl:197 [inlined]
[5] action(call::Symbol, libraries::Vector{Union{Base.PkgId, Module}}, sym::Symbol, file::String, args::Tuple{Makie.FigureAxisPlot}; options::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ FileIO ~/.julia/packages/FileIO/JA3Vl/src/loadsave.jl:185
[6] action
@ ~/.julia/packages/FileIO/JA3Vl/src/loadsave.jl:185 [inlined]
[7] #save#20
@ ~/.julia/packages/FileIO/JA3Vl/src/loadsave.jl:129 [inlined]
[8] save(file::String, args::Tuple{Makie.FigureAxisPlot})
@ FileIO ~/.julia/packages/FileIO/JA3Vl/src/loadsave.jl:126
[9] top-level scope
@ REPL[23]:1
As you can see, save("test.png", fig)
works correctly (so in particular, no additional packages need to be installed to save a PNG). However, if you get the second argument wrong (here I pass a tuple containing the figure instead of the figure), the error seems to suggest installing other packages, etc.
I think the right information is there (there's some MethodError
s and Argument does not support conversion to png
) but there's also a bunch of what feels to be misleading information, e.g.
ArgumentError: Package QuartzImageIO [dca85d43-d64c-5e67-8c65-017450d5d020] is required but does not seem to be installed:
- Run `Pkg.instantiate()` to install all recorded dependencies.
seems to be telling me to run Pkg.instantiate()
to try to fix the problem, or maybe add QuartzImageIO
.