Skip to content

Commit

Permalink
add a bit more information upon artifact load failure (#45537)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Jun 8, 2022
1 parent 54b92a7 commit d645436
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions stdlib/Artifacts/src/Artifacts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,8 @@ function _artifact_str(__module__, artifacts_toml, name, path_tail, artifact_dic

# If the artifact exists, we're in the happy path and we can immediately
# return the path to the artifact:
for dir in artifact_paths(hash; honor_overrides=true)
dirs = artifact_paths(hash; honor_overrides=true)
for dir in dirs
if isdir(dir)
return jointail(dir, path_tail)
end
Expand All @@ -549,7 +550,20 @@ function _artifact_str(__module__, artifacts_toml, name, path_tail, artifact_dic
end
error("Artifact $(repr(name)) is a lazy artifact; package developers must call `using LazyArtifacts` in $(__module__) before using lazy artifacts.")
end
error("Artifact $(repr(name)) was not installed correctly. Try `using Pkg; Pkg.instantiate()` to re-install all missing resources.")

path_str = if length(dirs) == 1
"path \"$(first(dirs))\". "
else
string("paths:\n", join(" " .* contractuser.(dirs), '\n'), '\n')
end

suggestion_str = if query_override(hash) !== nothing
"Check that your `Overrides.toml` file is correct (https://pkgdocs.julialang.org/v1/artifacts/#Overriding-artifact-locations)."
else
"Try `using Pkg; Pkg.instantiate()` to re-install all missing resources."
end

error("Artifact $(repr(name)) was not found by looking in the $(path_str)$suggestion_str")
end

raw"""
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Artifacts/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ end
mktempdir() do tempdir
with_artifacts_directory(tempdir) do
ex = @test_throws ErrorException artifact"HelloWorldC"
@test startswith(ex.value.msg, "Artifact \"HelloWorldC\" was not installed correctly. ")
@test startswith(ex.value.msg, "Artifact \"HelloWorldC\" was not found ")
ex = @test_throws ErrorException artifact"socrates"
@test startswith(ex.value.msg, "Artifact \"socrates\" is a lazy artifact; ")

Expand Down
2 changes: 1 addition & 1 deletion stdlib/LazyArtifacts/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mktempdir() do tempdir
@test isdir(socrates_dir)
end
ex = @test_throws ErrorException artifact"HelloWorldC"
@test startswith(ex.value.msg, "Artifact \"HelloWorldC\" was not installed correctly. ")
@test startswith(ex.value.msg, "Artifact \"HelloWorldC\" was not found")
end
end

Expand Down

0 comments on commit d645436

Please sign in to comment.