From 8b2c0f32939042e5d77da05d2825de6ec56487e9 Mon Sep 17 00:00:00 2001 From: Nathan Zimmerberg <39104088+nhz2@users.noreply.github.com> Date: Sun, 18 Aug 2024 18:35:20 -0400 Subject: [PATCH] Better error messages if artifact rename fails (#3827) * try rm to get better error messages * simplify changes * fix comment typo * rethrow InterruptException * Update error message * remove redundant error logging --- src/Artifacts.jl | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Artifacts.jl b/src/Artifacts.jl index 684f1556ef..d16bad6e0e 100644 --- a/src/Artifacts.jl +++ b/src/Artifacts.jl @@ -71,12 +71,16 @@ function _mv_temp_artifact_dir(temp_dir::String, new_path::String)::Nothing # However, `mv` defaults to `cp` if `rename` returns an error. # `cp` is not atomic, so avoid the potential of calling it. err = ccall(:jl_fs_rename, Int32, (Cstring, Cstring), temp_dir, new_path) - # Ignore rename error, but ensure `new_path` exists. - if !isdir(new_path) - error("$(repr(new_path)) could not be made") + if err ≥ 0 + # rename worked + chmod(new_path, filemode(dirname(new_path))) + set_readonly(new_path) + else + # Ignore rename error, if `new_path` exists. + if !isdir(new_path) + Base.uv_error("rename of $(repr(temp_dir)) to $(repr(new_path))", err) + end end - chmod(new_path, filemode(dirname(new_path))) - set_readonly(new_path) end nothing end @@ -374,7 +378,12 @@ function download_artifact( return err finally # Always attempt to cleanup - rm(temp_dir; recursive=true, force=true) + try + rm(temp_dir; recursive=true, force=true) + catch e + e isa InterruptException && rethrow() + @warn("Failed to clean up temporary directory $(repr(temp_dir))", exception=e) + end end return true end