Skip to content

Commit

Permalink
check parse before moving usage file into place (#3928)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth authored Jul 4, 2024
1 parent 0e5835e commit bcd3e76
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,15 @@ function write_env_usage(source_file::AbstractString, usage_filepath::AbstractSt
usage[k] = [Dict("time" => maximum(times))]
end

open(usage_file, "w") do io
TOML.print(io, usage, sorted=true)
tempfile = tempname()
try
open(tempfile, "w") do io
TOML.print(io, usage, sorted=true)
end
TOML.parsefile(tempfile) # compare to `usage` ?
mv(tempfile, usage_file; force=true) # only mv if parse succeeds
catch err
@error "Failed to write valid usage file `$usage_file`" tempfile
end
end
return
Expand Down

0 comments on commit bcd3e76

Please sign in to comment.