Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting to write an invalid value can leave the cache in a broken state #43

Open
simonbyrne opened this issue Sep 29, 2022 · 0 comments

Comments

@simonbyrne
Copy link
Contributor

If I attempt to write an object that can't be represented by the TOML format, it can leave the cache in an invalid state:

julia> using Preferences

julia> set_preferences!(Preferences, "a" => 1) # set a key to initialize the cache

julia> set_preferences!(Preferences, "b" => v"1.0") # attempt to write an invalid object, throws an error
ERROR: type `VersionNumber` is not a valid TOML type, pass a conversion function to `TOML.print`
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] _print(f::Nothing, io::IOStream, a::Dict{String, Any}, ks::Vector{String}; indent::Int64, first_block::Bool, sorted::Bool, by::Function)
    @ TOML.Internals.Printer /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/TOML/src/print.jl:112
 ...

julia> set_preferences!(Preferences, "c" => 1) # now write a valid object
ERROR: type `VersionNumber` is not a valid TOML type, pass a conversion function to `TOML.print`
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] _print(f::Nothing, io::IOStream, a::Dict{String, Any}, ks::Vector{String}; indent::Int64, first_block::Bool, sorted::Bool, by::Function)
    @ TOML.Internals.Printer /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/TOML/src/print.jl:112
  [3] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Any, NTuple{4, Symbol}, NamedTuple{(:indent, :first_block, :sorted, :by), Tuple{Int64, Bool, Bool, typeof(identity)}}})
    @ Base ./essentials.jl:731
  [4] _print(f::Nothing, io::IOStream, a::Dict{String, Any}, ks::Vector{String}; indent::Int64, first_block::Bool, sorted::Bool, by::Function)
    @ TOML.Internals.Printer /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/TOML/src/print.jl:147
  [5] #print#15
    @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/TOML/src/print.jl:170 [inlined]
  [6] (::Preferences.var"#4#5")(io::IOStream)
    @ Preferences ~/.julia/dev/Preferences/src/Preferences.jl:145
  [7] open(::Preferences.var"#4#5", ::String, ::Vararg{String}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base ./io.jl:384
  [8] open
    @ ./io.jl:381 [inlined]
  [9] set_preferences!(target_toml::String, pkg_name::String, pairs::Pair{String, Int64}; force::Bool)
    @ Preferences ~/.julia/dev/Preferences/src/Preferences.jl:144
 [10] set_preferences!
    @ ~/.julia/dev/Preferences/src/Preferences.jl:115 [inlined]
 [11] set_preferences!(u::Base.UUID, prefs::Pair{String, Int64}; export_prefs::Bool, active_project_only::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Preferences ~/.julia/dev/Preferences/src/Preferences.jl:283
 [12] set_preferences!
    @ ~/.julia/dev/Preferences/src/Preferences.jl:205 [inlined]
 [13] #set_preferences!#13
    @ ~/.julia/dev/Preferences/src/Preferences.jl:286 [inlined]
 [14] set_preferences!(m::Module, prefs::Pair{String, Int64})
    @ Preferences ~/.julia/dev/Preferences/src/Preferences.jl:285
 [15] top-level scope
    @ REPL[4]:1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant