diff --git a/base/loading.jl b/base/loading.jl index d3e4c0b5353af..2a5c2da5a1272 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -1292,6 +1292,19 @@ function compilecache_path(pkg::PkgId)::String end end +""" + PrecompileFailedException(pkg::PkgId, cachefile::String) + +Failure to precompile a module +""" +struct PrecompileFailedException <: Exception + pkg::PkgId + cachefile::String +end +function showerror(io::IO, ex::PrecompileFailedException) + print(io, "PrecompileFailedException: Failed to precompile $(ex.pkg) to $(ex.cachefile).") +end + """ Base.compilecache(module::PkgId) @@ -1357,7 +1370,7 @@ function compilecache(pkg::PkgId, path::String, internal_stderr::IO = stderr, in if p.exitcode == 125 return PrecompilableError() else - error("Failed to precompile $pkg to $cachefile.") + throw(PrecompileFailedException(pkg, cachefile)) end end diff --git a/test/precompile.jl b/test/precompile.jl index a16c6c6123c8e..61379ec3e99e9 100644 --- a/test/precompile.jl +++ b/test/precompile.jl @@ -463,8 +463,7 @@ try Base.require(Main, :FooBar2) error("the \"break me\" test failed") catch exc - isa(exc, ErrorException) || rethrow() - occursin("ERROR: LoadError: break me", exc.msg) && rethrow() + isa(exc, Base.PrecompileFailedException) || rethrow() end # Test that trying to eval into closed modules during precompilation is an error @@ -476,7 +475,7 @@ try @test_warn "Evaluation into the closed module `Base` breaks incremental compilation" try Base.require(Main, :FooBar3) catch exc - isa(exc, ErrorException) || rethrow() + isa(exc, Base.PrecompileFailedException) || rethrow() end end