Skip to content

Commit 2b33898

Browse files
check parse before moving usage file into place
1 parent 4e43058 commit 2b33898

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Types.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,15 @@ function write_env_usage(source_file::AbstractString, usage_filepath::AbstractSt
617617
usage[k] = [Dict("time" => maximum(times))]
618618
end
619619

620-
open(usage_file, "w") do io
621-
TOML.print(io, usage, sorted=true)
620+
tempfile = tempname()
621+
try
622+
open(tempfile, "w") do io
623+
TOML.print(io, usage, sorted=true)
624+
end
625+
TOML.parsefile(tempfile) # compare to `usage` ?
626+
mv(tempfile, usage_file; force=true) # only mv if parse succeeds
627+
catch err
628+
@error "Failed to write valid usage file `$usage_file`" tempfile
622629
end
623630
end
624631
return

0 commit comments

Comments
 (0)