From bc3b67cbc9d9734c25105f26cf4208385a265d07 Mon Sep 17 00:00:00 2001 From: Qian Long Date: Wed, 8 Nov 2023 22:52:50 +0800 Subject: [PATCH 01/19] Raise an error when using include_dependency with non-existent file Since depending on a non-existent file or directory is strange, raise an error instead of silently triggering precompilation. Fixes #52063 --- base/loading.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/base/loading.jl b/base/loading.jl index 065b287b32dd6..824b8cb1cc99d 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -2063,6 +2063,7 @@ function _include_dependency(mod::Module, _path::AbstractString; track_content=t # use mtime=-1.0 here so that fsize==0 && mtime==0.0 corresponds to a missing include_dependency push!(_require_dependencies, (mod, path, filesize(path), hash, -1.0)) else + isfile(path) || throw(ArgumentError("$(repr(path)) is not a readable file")) push!(_require_dependencies, (mod, path, UInt64(0), UInt32(0), mtime(path))) end end From b9ad42217ce1b42f69803f7af8dd4c87731c9ca2 Mon Sep 17 00:00:00 2001 From: Florian Atteneder Date: Fri, 7 Jun 2024 20:22:03 +0200 Subject: [PATCH 02/19] add unit test --- test/precompile.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/precompile.jl b/test/precompile.jl index ce606d166f695..cd34093fb8718 100644 --- a/test/precompile.jl +++ b/test/precompile.jl @@ -1996,4 +1996,14 @@ precompile_test_harness("Generated Opaque") do load_path end end +precompile_test_harness("Issue #52063") do load_path + write(joinpath(load_path, "I52063.jl"), + """ + module I52063 + include_dependency("i_do_not_exist.jl") + end + """) + @test_throws ArgumentError Base.compilecache(Base.PkgId("I50538")) +end + finish_precompile_test!() From 2a2644f8e7a6564c88a0548d7cd899dc83dca24c Mon Sep 17 00:00:00 2001 From: Florian Atteneder Date: Sun, 11 Feb 2024 12:55:14 +0100 Subject: [PATCH 03/19] raise error when path is file or directory --- base/loading.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/loading.jl b/base/loading.jl index 824b8cb1cc99d..2d392b9c98823 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -2063,7 +2063,7 @@ function _include_dependency(mod::Module, _path::AbstractString; track_content=t # use mtime=-1.0 here so that fsize==0 && mtime==0.0 corresponds to a missing include_dependency push!(_require_dependencies, (mod, path, filesize(path), hash, -1.0)) else - isfile(path) || throw(ArgumentError("$(repr(path)) is not a readable file")) + ispath(path) || throw(ArgumentError("$(repr(path)): No such file or directory")) push!(_require_dependencies, (mod, path, UInt64(0), UInt32(0), mtime(path))) end end From ba13fa767d670d8ed18f862c45eaf8577438ffd6 Mon Sep 17 00:00:00 2001 From: Florian Atteneder Date: Sun, 11 Feb 2024 13:03:39 +0100 Subject: [PATCH 04/19] fix test by generating include_dependency files before precompilation --- test/precompile.jl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/test/precompile.jl b/test/precompile.jl index cd34093fb8718..515d1a1559be1 100644 --- a/test/precompile.jl +++ b/test/precompile.jl @@ -6,6 +6,8 @@ using REPL # doc lookup function include("precompile_utils.jl") Foo_module = :Foo4b3a94a1a081a8cb +foo_incl_dep = :foo4b3a94a1a081a8cb +bar_incl_dep = :bar4b3a94a1a081a8cb Foo2_module = :F2oo4b3a94a1a081a8cb FooBase_module = :FooBase4b3a94a1a081a8cb @eval module ConflictingBindings @@ -75,6 +77,8 @@ precompile_test_harness(false) do dir Foo_file = joinpath(dir, "$Foo_module.jl") Foo2_file = joinpath(dir, "$Foo2_module.jl") FooBase_file = joinpath(dir, "$FooBase_module.jl") + foo_file = joinpath(dir, "$foo_incl_dep.jl") + bar_file = joinpath(dir, "$bar_incl_dep.jl") write(FooBase_file, """ @@ -123,11 +127,11 @@ precompile_test_harness(false) do dir # test that docs get reconnected @doc "foo function" foo(x) = x + 1 - include_dependency("foo.jl") - include_dependency("foo.jl") + include_dependency("$foo_incl_dep.jl") + include_dependency("$foo_incl_dep.jl") module Bar public bar - include_dependency("bar.jl") + include_dependency("$bar_incl_dep.jl") end @doc "Bar module" Bar # this needs to define the META dictionary via eval @eval Bar @doc "bar function" bar(x) = x + 2 @@ -270,6 +274,8 @@ precompile_test_harness(false) do dir oid_mat_int = objectid(a_mat_int) end """) + # Issue #52063 + touch(foo_file); touch(bar_file) # Issue #12623 @test __precompile__(false) === nothing @@ -412,8 +418,7 @@ precompile_test_harness(false) do dir modules, (deps, _, requires), required_modules, _... = Base.parse_cache_header(cachefile) discard_module = mod_fl_mt -> mod_fl_mt.filename @test modules == [ Base.PkgId(Foo) => Base.module_build_id(Foo) % UInt64 ] - # foo.jl and bar.jl are never written to disk, so they are not relocatable - @test map(x -> x.filename, deps) == [ Foo_file, joinpath("@depot", "foo.jl"), joinpath("@depot", "bar.jl") ] + @test map(x -> x.filename, deps) == [ Foo_file, joinpath("@depot", foo_file), joinpath("@depot", bar_file) ] @test requires == [ Base.PkgId(Foo) => Base.PkgId(string(FooBase_module)), Base.PkgId(Foo) => Base.PkgId(Foo2), Base.PkgId(Foo) => Base.PkgId(Test), @@ -422,7 +427,7 @@ precompile_test_harness(false) do dir @test !isempty(srctxt) && srctxt == read(Foo_file, String) @test_throws ErrorException Base.read_dependency_src(cachefile, "/tmp/nonexistent.txt") # dependencies declared with `include_dependency` should not be stored - @test_throws ErrorException Base.read_dependency_src(cachefile, joinpath(dir, "foo.jl")) + @test_throws ErrorException Base.read_dependency_src(cachefile, joinpath(dir, foo_file)) modules, deps1 = Base.cache_dependencies(cachefile) modules_ok = merge( From 34a887637abece9cb64de44615ee5b57c7c9c2bd Mon Sep 17 00:00:00 2001 From: Florian Atteneder Date: Sun, 11 Feb 2024 16:01:18 +0100 Subject: [PATCH 05/19] apply ispath & uperm checks to any included files --- base/loading.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/loading.jl b/base/loading.jl index 2d392b9c98823..89c3106711ccd 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -2056,6 +2056,8 @@ function _include_dependency(mod::Module, _path::AbstractString; track_content=t else path = normpath(joinpath(dirname(prev), _path)) end + ispath(path) || throw(ArgumentError("$(repr(path)): No such file or directory")) + uperm(path) & 0x04 == 0x04 || throw(ArgumentError("$(repr(path)): Missing read permission")) if _track_dependencies[] @lock require_lock begin if track_content @@ -2063,7 +2065,6 @@ function _include_dependency(mod::Module, _path::AbstractString; track_content=t # use mtime=-1.0 here so that fsize==0 && mtime==0.0 corresponds to a missing include_dependency push!(_require_dependencies, (mod, path, filesize(path), hash, -1.0)) else - ispath(path) || throw(ArgumentError("$(repr(path)): No such file or directory")) push!(_require_dependencies, (mod, path, UInt64(0), UInt32(0), mtime(path))) end end From 1a464991642ca31bd8b44d3552e5e249d9ebd738 Mon Sep 17 00:00:00 2001 From: Florian Atteneder Date: Sun, 11 Feb 2024 16:01:32 +0100 Subject: [PATCH 06/19] update test --- test/precompile.jl | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/test/precompile.jl b/test/precompile.jl index 515d1a1559be1..404881245cb74 100644 --- a/test/precompile.jl +++ b/test/precompile.jl @@ -2002,13 +2002,19 @@ precompile_test_harness("Generated Opaque") do load_path end precompile_test_harness("Issue #52063") do load_path - write(joinpath(load_path, "I52063.jl"), - """ - module I52063 - include_dependency("i_do_not_exist.jl") - end - """) - @test_throws ArgumentError Base.compilecache(Base.PkgId("I50538")) + fname = joinpath(load_path, "i_do_not_exist.jl") + @test_throws ArgumentError("$(repr(fname)): No such file or directory") include_dependency(fname) + touch(fname) + @test include_dependency(fname) === nothing + chmod(fname, 0x000) + @test_throws ArgumentError("$(repr(fname)): Missing read permission") include_dependency(fname) + dir = mktempdir() do dir + @test include_dependency(dir) === nothing + chmod(dir, 0x000) + @test_throws ArgumentError("$(repr(dir)): Missing read permission") include_dependency(dir) + dir + end + @test_throws ArgumentError("$(repr(dir)): No such file or directory") include_dependency(dir) end finish_precompile_test!() From 4ac897a8d9d2d0310353e9aedb04e9035b312415 Mon Sep 17 00:00:00 2001 From: Florian Atteneder Date: Sun, 11 Feb 2024 18:12:26 +0100 Subject: [PATCH 07/19] fix loading tests --- test/loading.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/loading.jl b/test/loading.jl index 9230bc75599e6..4cf07949e6472 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -650,9 +650,9 @@ end # normalization of paths by include (#26424) @test begin exc = try; include("./notarealfile.jl"); "unexpectedly reached!"; catch exc; exc; end - @test exc isa SystemError - exc.prefix -end == "opening file $(repr(joinpath(@__DIR__, "notarealfile.jl")))" + @test exc isa ArgumentError + exc.msg +end == "$(repr(joinpath(@__DIR__, "notarealfile.jl"))): No such file or directory" old_act_proj = Base.ACTIVE_PROJECT[] pushfirst!(LOAD_PATH, "@") @@ -1549,7 +1549,7 @@ end end file = joinpath(depot, "dev", "non-existent.jl") - @test_throws SystemError("opening file $(repr(file))") include(file) + @test_throws ArgumentError("$(repr(file)): No such file or directory") include(file) end end From e1a717ce0edb7fa6874535876894e714c8d186bf Mon Sep 17 00:00:00 2001 From: Florian Atteneder Date: Fri, 7 Jun 2024 20:22:19 +0200 Subject: [PATCH 08/19] move tests to test/loading.jl --- test/loading.jl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/loading.jl b/test/loading.jl index 4cf07949e6472..7deb40df34877 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -1550,6 +1550,19 @@ end file = joinpath(depot, "dev", "non-existent.jl") @test_throws ArgumentError("$(repr(file)): No such file or directory") include(file) + touch(file) + @test include_dependency(file) === nothing + chmod(file, 0x000) + @test_throws ArgumentError("$(repr(file)): Missing read permission") include_dependency(file) + + # same for include_dependency: #52063 + dir = mktempdir() do dir + @test include_dependency(dir) === nothing + chmod(dir, 0x000) + @test_throws ArgumentError("$(repr(dir)): Missing read permission") include_dependency(dir) + dir + end + @test_throws ArgumentError("$(repr(dir)): No such file or directory") include_dependency(dir) end end From 9d81ed3530f7112960ebe772ff86396af71fcfee Mon Sep 17 00:00:00 2001 From: Florian Atteneder Date: Tue, 20 Feb 2024 20:22:56 +0100 Subject: [PATCH 09/19] use Sys.readable for permission check --- base/loading.jl | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/base/loading.jl b/base/loading.jl index 89c3106711ccd..affa5d6fff550 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -2049,16 +2049,25 @@ const include_callbacks = Any[] const _concrete_dependencies = Pair{PkgId,UInt128}[] # these dependency versions are "set in stone", and the process should try to avoid invalidating them const _require_dependencies = Any[] # a list of (mod, abspath, fsize, hash, mtime) tuples that are the file dependencies of the module currently being precompiled const _track_dependencies = Ref(false) # set this to true to track the list of file dependencies -function _include_dependency(mod::Module, _path::AbstractString; track_content=true) +function _include_dependency(mod::Module, _path::AbstractString; track_content=true, + path_maybe_dir=false) prev = source_path(nothing) if prev === nothing path = abspath(_path) else path = normpath(joinpath(dirname(prev), _path)) end - ispath(path) || throw(ArgumentError("$(repr(path)): No such file or directory")) - uperm(path) & 0x04 == 0x04 || throw(ArgumentError("$(repr(path)): Missing read permission")) - if _track_dependencies[] + if !_track_dependencies[] + if !path_maybe_dir && !isfile(path) + throw(ArgumentError("including $(repr(path)): No such file")) + elseif path_maybe_dir && !ispath(path) + throw(ArgumentError("including $(repr(path)): No such file or directory")) + end + readable = @static Sys.iswindows() ? uperm(path) & 0x04 == 0x04 : Sys.isreadable(path) + if !readable + throw(ArgumentError("including $(repr(path)): Missing read permission")) + end + else @lock require_lock begin if track_content hash = isdir(path) ? _crc32c(join(readdir(path))) : open(_crc32c, path, "r") @@ -2088,7 +2097,7 @@ no effect outside of compilation. Keyword argument `track_content` requires at least Julia 1.11. """ function include_dependency(path::AbstractString; track_content::Bool=false) - _include_dependency(Main, path, track_content=track_content) + _include_dependency(Main, path, track_content=track_content, path_maybe_dir=true) return nothing end From 60146297503a8c18846f9deb167bee7e07060b31 Mon Sep 17 00:00:00 2001 From: Florian Atteneder Date: Tue, 20 Feb 2024 20:24:05 +0100 Subject: [PATCH 10/19] update test --- test/loading.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/loading.jl b/test/loading.jl index 7deb40df34877..83a5ba56c4a37 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -652,7 +652,7 @@ end exc = try; include("./notarealfile.jl"); "unexpectedly reached!"; catch exc; exc; end @test exc isa ArgumentError exc.msg -end == "$(repr(joinpath(@__DIR__, "notarealfile.jl"))): No such file or directory" +end == "including $(repr(joinpath(@__DIR__, "notarealfile.jl"))): No such file" old_act_proj = Base.ACTIVE_PROJECT[] pushfirst!(LOAD_PATH, "@") @@ -1549,20 +1549,20 @@ end end file = joinpath(depot, "dev", "non-existent.jl") - @test_throws ArgumentError("$(repr(file)): No such file or directory") include(file) + @test_throws ArgumentError("including $(repr(file)): No such file") include(file) touch(file) @test include_dependency(file) === nothing chmod(file, 0x000) - @test_throws ArgumentError("$(repr(file)): Missing read permission") include_dependency(file) + @test_throws ArgumentError("including $(repr(file)): Missing read permission") include_dependency(file) # same for include_dependency: #52063 dir = mktempdir() do dir @test include_dependency(dir) === nothing chmod(dir, 0x000) - @test_throws ArgumentError("$(repr(dir)): Missing read permission") include_dependency(dir) + @test_throws ArgumentError("including $(repr(dir)): Missing read permission") include_dependency(dir) dir end - @test_throws ArgumentError("$(repr(dir)): No such file or directory") include_dependency(dir) + @test_throws ArgumentError("including $(repr(dir)): No such file or directory") include_dependency(dir) end end From 8e1f253995a238a1002fbdcf04ae72d4fe2a54d4 Mon Sep 17 00:00:00 2001 From: Florian Atteneder Date: Sun, 25 Feb 2024 15:40:24 +0100 Subject: [PATCH 11/19] omit permission check because we can't implement that reliably on windows --- base/loading.jl | 4 ---- test/loading.jl | 3 --- 2 files changed, 7 deletions(-) diff --git a/base/loading.jl b/base/loading.jl index affa5d6fff550..4d0fc8c3d18f2 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -2063,10 +2063,6 @@ function _include_dependency(mod::Module, _path::AbstractString; track_content=t elseif path_maybe_dir && !ispath(path) throw(ArgumentError("including $(repr(path)): No such file or directory")) end - readable = @static Sys.iswindows() ? uperm(path) & 0x04 == 0x04 : Sys.isreadable(path) - if !readable - throw(ArgumentError("including $(repr(path)): Missing read permission")) - end else @lock require_lock begin if track_content diff --git a/test/loading.jl b/test/loading.jl index 83a5ba56c4a37..b7d17ecbe2c7e 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -1553,13 +1553,10 @@ end touch(file) @test include_dependency(file) === nothing chmod(file, 0x000) - @test_throws ArgumentError("including $(repr(file)): Missing read permission") include_dependency(file) # same for include_dependency: #52063 dir = mktempdir() do dir @test include_dependency(dir) === nothing - chmod(dir, 0x000) - @test_throws ArgumentError("including $(repr(dir)): Missing read permission") include_dependency(dir) dir end @test_throws ArgumentError("including $(repr(dir)): No such file or directory") include_dependency(dir) From f386bc9bac809dd98dad60b790fde40fd479da09 Mon Sep 17 00:00:00 2001 From: Florian Date: Mon, 22 Apr 2024 22:01:29 +0200 Subject: [PATCH 12/19] Revert to using SystemError instead of ArgumentError Co-authored-by: Jameson Nash --- base/loading.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/loading.jl b/base/loading.jl index 4d0fc8c3d18f2..eb02ebd0e0810 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -2059,9 +2059,9 @@ function _include_dependency(mod::Module, _path::AbstractString; track_content=t end if !_track_dependencies[] if !path_maybe_dir && !isfile(path) - throw(ArgumentError("including $(repr(path)): No such file")) + throw(SystemError("including file $(repr(path))", Libc.ENOENT)) elseif path_maybe_dir && !ispath(path) - throw(ArgumentError("including $(repr(path)): No such file or directory")) + throw(SystemError("including file or folder $(repr(path))", Libc.ENOENT)) end else @lock require_lock begin From d2260a4fcaa31c8dbec7f017de8214b08fe09297 Mon Sep 17 00:00:00 2001 From: Florian Atteneder Date: Mon, 22 Apr 2024 22:00:27 +0200 Subject: [PATCH 13/19] fix spelling --- base/loading.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/base/loading.jl b/base/loading.jl index eb02ebd0e0810..ab853207ab268 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -2050,7 +2050,7 @@ const _concrete_dependencies = Pair{PkgId,UInt128}[] # these dependency versions const _require_dependencies = Any[] # a list of (mod, abspath, fsize, hash, mtime) tuples that are the file dependencies of the module currently being precompiled const _track_dependencies = Ref(false) # set this to true to track the list of file dependencies function _include_dependency(mod::Module, _path::AbstractString; track_content=true, - path_maybe_dir=false) + path_may_be_dir=false) prev = source_path(nothing) if prev === nothing path = abspath(_path) @@ -2058,9 +2058,9 @@ function _include_dependency(mod::Module, _path::AbstractString; track_content=t path = normpath(joinpath(dirname(prev), _path)) end if !_track_dependencies[] - if !path_maybe_dir && !isfile(path) + if !path_may_be_dir && !isfile(path) throw(SystemError("including file $(repr(path))", Libc.ENOENT)) - elseif path_maybe_dir && !ispath(path) + elseif path_may_be_dir && !ispath(path) throw(SystemError("including file or folder $(repr(path))", Libc.ENOENT)) end else @@ -2093,7 +2093,7 @@ no effect outside of compilation. Keyword argument `track_content` requires at least Julia 1.11. """ function include_dependency(path::AbstractString; track_content::Bool=false) - _include_dependency(Main, path, track_content=track_content, path_maybe_dir=true) + _include_dependency(Main, path, track_content=track_content, path_may_be_dir=true) return nothing end From 42215a561a025cc4b4c8075a7449c8a490a943d2 Mon Sep 17 00:00:00 2001 From: Florian Atteneder Date: Mon, 22 Apr 2024 22:01:12 +0200 Subject: [PATCH 14/19] use isreadable instead of ispath --- base/loading.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/loading.jl b/base/loading.jl index ab853207ab268..27dd5f9da4588 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -2060,7 +2060,7 @@ function _include_dependency(mod::Module, _path::AbstractString; track_content=t if !_track_dependencies[] if !path_may_be_dir && !isfile(path) throw(SystemError("including file $(repr(path))", Libc.ENOENT)) - elseif path_may_be_dir && !ispath(path) + elseif path_may_be_dir && !Filesystem.isreadable(path) throw(SystemError("including file or folder $(repr(path))", Libc.ENOENT)) end else From 772d378d759c9583d47d2c5782dffe5d84380931 Mon Sep 17 00:00:00 2001 From: Florian Atteneder Date: Mon, 22 Apr 2024 22:04:41 +0200 Subject: [PATCH 15/19] update tests to work with SystemError again --- test/loading.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/loading.jl b/test/loading.jl index b7d17ecbe2c7e..5b7f8186fc08f 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -650,9 +650,9 @@ end # normalization of paths by include (#26424) @test begin exc = try; include("./notarealfile.jl"); "unexpectedly reached!"; catch exc; exc; end - @test exc isa ArgumentError - exc.msg -end == "including $(repr(joinpath(@__DIR__, "notarealfile.jl"))): No such file" + @test exc isa SystemError + exc.prefix +end == "including file $(repr(joinpath(@__DIR__, "notarealfile.jl"))): No such file" old_act_proj = Base.ACTIVE_PROJECT[] pushfirst!(LOAD_PATH, "@") @@ -1549,7 +1549,7 @@ end end file = joinpath(depot, "dev", "non-existent.jl") - @test_throws ArgumentError("including $(repr(file)): No such file") include(file) + @test_throws SystemError("including file $(repr(file)): No such file") include(file) touch(file) @test include_dependency(file) === nothing chmod(file, 0x000) @@ -1559,7 +1559,7 @@ end @test include_dependency(dir) === nothing dir end - @test_throws ArgumentError("including $(repr(dir)): No such file or directory") include_dependency(dir) + @test_throws SystemError("including $(repr(dir)): No such file or directory") include_dependency(dir) end end From 9873c7ac0db0dcfeb2c06e781b76be483ed9aff6 Mon Sep 17 00:00:00 2001 From: Florian Date: Tue, 23 Apr 2024 21:43:08 +0200 Subject: [PATCH 16/19] Update tests --- test/loading.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/loading.jl b/test/loading.jl index 5b7f8186fc08f..5ce20b25f8f74 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -652,7 +652,7 @@ end exc = try; include("./notarealfile.jl"); "unexpectedly reached!"; catch exc; exc; end @test exc isa SystemError exc.prefix -end == "including file $(repr(joinpath(@__DIR__, "notarealfile.jl"))): No such file" +end == "including file $(repr(joinpath(@__DIR__, "notarealfile.jl")))" old_act_proj = Base.ACTIVE_PROJECT[] pushfirst!(LOAD_PATH, "@") @@ -1549,7 +1549,7 @@ end end file = joinpath(depot, "dev", "non-existent.jl") - @test_throws SystemError("including file $(repr(file)): No such file") include(file) + @test_throws SystemError("including file $(repr(file))") include(file) touch(file) @test include_dependency(file) === nothing chmod(file, 0x000) @@ -1559,7 +1559,7 @@ end @test include_dependency(dir) === nothing dir end - @test_throws SystemError("including $(repr(dir)): No such file or directory") include_dependency(dir) + @test_throws SystemError("including file or directory $(repr(dir))") include_dependency(dir) end end From 5861922cba0927509863cd6dff4cc1a08d7a0f2a Mon Sep 17 00:00:00 2001 From: Florian Date: Tue, 23 Apr 2024 23:47:49 +0200 Subject: [PATCH 17/19] Update test/loading.jl --- test/loading.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/loading.jl b/test/loading.jl index 5ce20b25f8f74..e9bf630953ca5 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -1559,7 +1559,7 @@ end @test include_dependency(dir) === nothing dir end - @test_throws SystemError("including file or directory $(repr(dir))") include_dependency(dir) + @test_throws SystemError("including file or folder $(repr(dir))") include_dependency(dir) end end From 2c96a66318fa75595842be4213d648008dafe14b Mon Sep 17 00:00:00 2001 From: Florian Atteneder Date: Fri, 7 Jun 2024 19:35:19 +0200 Subject: [PATCH 18/19] revert error msg in SystemError --- base/loading.jl | 4 ++-- test/loading.jl | 6 +++--- test/precompile.jl | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/base/loading.jl b/base/loading.jl index 27dd5f9da4588..f432268208008 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -2059,9 +2059,9 @@ function _include_dependency(mod::Module, _path::AbstractString; track_content=t end if !_track_dependencies[] if !path_may_be_dir && !isfile(path) - throw(SystemError("including file $(repr(path))", Libc.ENOENT)) + throw(SystemError("opening file $(repr(path))", Libc.ENOENT)) elseif path_may_be_dir && !Filesystem.isreadable(path) - throw(SystemError("including file or folder $(repr(path))", Libc.ENOENT)) + throw(SystemError("opening file or folder $(repr(path))", Libc.ENOENT)) end else @lock require_lock begin diff --git a/test/loading.jl b/test/loading.jl index e9bf630953ca5..1cd9154d587d1 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -652,7 +652,7 @@ end exc = try; include("./notarealfile.jl"); "unexpectedly reached!"; catch exc; exc; end @test exc isa SystemError exc.prefix -end == "including file $(repr(joinpath(@__DIR__, "notarealfile.jl")))" +end == "opening file $(repr(joinpath(@__DIR__, "notarealfile.jl")))" old_act_proj = Base.ACTIVE_PROJECT[] pushfirst!(LOAD_PATH, "@") @@ -1549,7 +1549,7 @@ end end file = joinpath(depot, "dev", "non-existent.jl") - @test_throws SystemError("including file $(repr(file))") include(file) + @test_throws SystemError("opening file $(repr(file))") include(file) touch(file) @test include_dependency(file) === nothing chmod(file, 0x000) @@ -1559,7 +1559,7 @@ end @test include_dependency(dir) === nothing dir end - @test_throws SystemError("including file or folder $(repr(dir))") include_dependency(dir) + @test_throws SystemError("opening file or folder $(repr(dir))") include_dependency(dir) end end diff --git a/test/precompile.jl b/test/precompile.jl index 404881245cb74..d25519cbb5ec6 100644 --- a/test/precompile.jl +++ b/test/precompile.jl @@ -2003,18 +2003,18 @@ end precompile_test_harness("Issue #52063") do load_path fname = joinpath(load_path, "i_do_not_exist.jl") - @test_throws ArgumentError("$(repr(fname)): No such file or directory") include_dependency(fname) + @test_throws SystemError("opening file or folder $(repr(fname))") include_dependency(fname) touch(fname) @test include_dependency(fname) === nothing chmod(fname, 0x000) - @test_throws ArgumentError("$(repr(fname)): Missing read permission") include_dependency(fname) + @test_throws SystemError("opening file or folder $(repr(fname))", Libc.ENOENT) include_dependency(fname) dir = mktempdir() do dir @test include_dependency(dir) === nothing chmod(dir, 0x000) - @test_throws ArgumentError("$(repr(dir)): Missing read permission") include_dependency(dir) + @test_throws SystemError("opening file or folder $(repr(dir))", Libc.ENOENT) include_dependency(dir) dir end - @test_throws ArgumentError("$(repr(dir)): No such file or directory") include_dependency(dir) + @test_throws SystemError("opening file or folder $(repr(dir))") include_dependency(dir) end finish_precompile_test!() From 85e067acb79eeefc00ba3a75c60b0348aa1927fa Mon Sep 17 00:00:00 2001 From: Florian Atteneder Date: Thu, 20 Jun 2024 20:38:20 +0200 Subject: [PATCH 19/19] only check error msg contained in thrown SystemError --- test/loading.jl | 16 ++++++++++++++-- test/precompile.jl | 32 ++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/test/loading.jl b/test/loading.jl index 1cd9154d587d1..72589d4210adc 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -1549,7 +1549,13 @@ end end file = joinpath(depot, "dev", "non-existent.jl") - @test_throws SystemError("opening file $(repr(file))") include(file) + @test try + include(file); false + catch e + @test e isa SystemError + @test e.prefix == "opening file $(repr(file))" + true + end touch(file) @test include_dependency(file) === nothing chmod(file, 0x000) @@ -1559,7 +1565,13 @@ end @test include_dependency(dir) === nothing dir end - @test_throws SystemError("opening file or folder $(repr(dir))") include_dependency(dir) + @test try + include_dependency(dir); false + catch e + @test e isa SystemError + @test e.prefix == "opening file or folder $(repr(dir))" + true + end end end diff --git a/test/precompile.jl b/test/precompile.jl index d25519cbb5ec6..e4d2b65c66c4b 100644 --- a/test/precompile.jl +++ b/test/precompile.jl @@ -2003,18 +2003,42 @@ end precompile_test_harness("Issue #52063") do load_path fname = joinpath(load_path, "i_do_not_exist.jl") - @test_throws SystemError("opening file or folder $(repr(fname))") include_dependency(fname) + @test try + include_dependency(fname); false + catch e + @test e isa SystemError + @test e.prefix == "opening file or folder $(repr(fname))" + true + end touch(fname) @test include_dependency(fname) === nothing chmod(fname, 0x000) - @test_throws SystemError("opening file or folder $(repr(fname))", Libc.ENOENT) include_dependency(fname) + @test try + include_dependency(fname); false + catch e + @test e isa SystemError + @test e.prefix == "opening file or folder $(repr(fname))" + true + end broken=Sys.iswindows() dir = mktempdir() do dir @test include_dependency(dir) === nothing chmod(dir, 0x000) - @test_throws SystemError("opening file or folder $(repr(dir))", Libc.ENOENT) include_dependency(dir) + @test try + include_dependency(dir); false + catch e + @test e isa SystemError + @test e.prefix == "opening file or folder $(repr(dir))" + true + end broken=Sys.iswindows() dir end - @test_throws SystemError("opening file or folder $(repr(dir))") include_dependency(dir) + @test try + include_dependency(dir); false + catch e + @test e isa SystemError + @test e.prefix == "opening file or folder $(repr(dir))" + true + end end finish_precompile_test!()