From 2fe5792c581fa027ef8f595b3488b616f22ba640 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Thu, 8 Aug 2024 18:01:59 +0200 Subject: [PATCH 1/3] handle if the expected cache file is missing --- base/loading.jl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/base/loading.jl b/base/loading.jl index c273e4505701f..027af3942edce 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -3664,7 +3664,16 @@ end ignore_loaded::Bool=false, requested_flags::CacheFlags=CacheFlags(), reasons::Union{Dict{String,Int},Nothing}=nothing, stalecheck::Bool=true) # n.b.: this function does nearly all of the file validation, not just those checks related to stale, so the name is potentially unclear - io = open(cachefile, "r") + io = try + open(cachefile, "r") + catch e + if e isa SystemError && e.errno == ENOENT + @debug "Rejecting cache file $cachefile for $modkey because it does not exist" + return true + else + rethrow() + end + end try checksum = isvalid_cache_header(io) if iszero(checksum) From ea8223bef23edeae8ed3748e8b7fddff9ca78a1b Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Thu, 8 Aug 2024 18:14:51 +0200 Subject: [PATCH 2/3] add test --- test/precompile.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/precompile.jl b/test/precompile.jl index 3241ee8b25a35..f45eb4bb1e79e 100644 --- a/test/precompile.jl +++ b/test/precompile.jl @@ -597,6 +597,10 @@ precompile_test_harness(false) do dir @test Base.invokelatest(Baz.baz) === 1 @test Baz === UseBaz.Baz + # should not throw if the cachefile does not exist + @test !isfile("DoesNotExist.ji") + @test Base.stale_cachefile("", "DoesNotExist.ji") === true + # Issue #12720 FooBar1_file = joinpath(dir, "FooBar1.jl") write(FooBar1_file, From af42455e9ce733b6cf377c9f2a21b6ae80f73a72 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Thu, 8 Aug 2024 19:53:13 +0200 Subject: [PATCH 3/3] fix --- base/loading.jl | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/base/loading.jl b/base/loading.jl index 027af3942edce..3eca91613b4e5 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -3666,13 +3666,10 @@ end # n.b.: this function does nearly all of the file validation, not just those checks related to stale, so the name is potentially unclear io = try open(cachefile, "r") - catch e - if e isa SystemError && e.errno == ENOENT - @debug "Rejecting cache file $cachefile for $modkey because it does not exist" - return true - else - rethrow() - end + catch ex + ex isa IOError || ex isa SystemError || rethrow() + @debug "Rejecting cache file $cachefile for $modkey because it could not be opened" isfile(cachefile) + return true end try checksum = isvalid_cache_header(io)