Deserialization error (StackOverflow) crashes Julia and can not be caught

I have the following function which retrieves the content of a cache stored as a serialized Julia object:

"""
    fromcache(key::Any, expiration::Int; dir::String = "") :: Union{Nothing,Any}

Retrieves from cache the object stored under the `key` key if the `expiration` delta (in seconds) is in the future.
"""
function fromcache(key::Any, expiration::Int; dir::String = "") :: Union{Nothing,Any}
  file_path = cache_path(string(key), dir = dir)

  ( ! isfile(file_path) || stat(file_path).ctime + expiration < time() ) && return nothing

  open(file_path) do io
    Serialization.deserialize(io)
  end
end

It looks like something got corrupted and attempting to deserialize results in a Stack Overflow Exception:

Error: 2021-08-03 14:19:08 StackOverflowError:
│ Stacktrace:
│   [1] deserialize_array(s::Serialization.Serializer{IOStream})
│     @ Serialization /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:1176
│   [2] handle_deserialize(s::Serialization.Serializer{IOStream}, b::Int32)
│     @ Serialization /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:833
│   [3] deserialize(s::Serialization.Serializer{IOStream}, t::DataType)
│     @ Serialization /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:1403
│   [4] handle_deserialize(s::Serialization.Serializer{IOStream}, b::Int32)
│     @ Serialization /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:846
│ --- the last 2 lines are repeated 1 more time ---
│   [7] deserialize(s::Serialization.Serializer{IOStream})
│     @ Serialization /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:782
│   [8] handle_deserialize(s::Serialization.Serializer{IOStream}, b::Int32)
│     @ Serialization /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:888
│   [9] deserialize
│     @ /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:782 [inlined]
│  [10] deserialize(s::IOStream)
│     @ Serialization /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:769
│  [11] #5
│     @ ~/.julia/dev/Genie/src/cache_adapters/FileCache.jl:34 [inlined]
│  [12] open(f::Genie.Cache.FileCache.var"#5#6", args::String; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
│     @ Base ./io.jl:330
│  [13] open
│     @ ./io.jl:328 [inlined]
│  [14] fromcache(key::String, expiration::Int64; dir::String)
│     @ Genie.Cache.FileCache ~/.julia/dev/Genie/src/cache_adapters/FileCache.jl:33
# .... more output ...

Attempting to try/catch this exception anywhere (in the function or in any other function up the execution stack) results in Julia crashing with 77458 Bus error: 10

How can this be handled as the app can not run unless the exception is caught somewhere in the stack, and the faulty file is removed?


julia> versioninfo()
Julia Version 1.6.2
Commit 1b93d53fc4 (2021-07-14 15:36 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.7.0)
  CPU: Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)