Repository: JuliaLang/julia
File: stdlib/Artifacts/src/Artifacts.jl (Julia)

Code before:
end

function __artifact_str(__module__, artifacts_toml, name, path_tail, artifact_dict, hash, platform, ::Val{LazyArtifacts}) where LazyArtifacts
    pkg = Base.PkgId(__module__)
    if pkg.uuid !== nothing
        # Process overrides for this UUID, if we know what it is
        process_overrides(artifact_dict, pkg.uuid)
    end

    # If the artifact exists, we're in the happy path and we can immediately
    # return the path to the artifact:
    dirs = artifact_paths(hash; honor_overrides=true)
    for dir in dirs
        if isdir(dir)
            return jointail(dir, path_tail)
        end
    end

    # If not, try determining what went wrong:
    meta = artifact_meta(name, artifact_dict, artifacts_toml; platform)
    if meta !== nothing && get(meta, "lazy", false)
        if LazyArtifacts isa Module && isdefined(LazyArtifacts, :ensure_artifact_installed)
            if nameof(LazyArtifacts) in (:Pkg, :Artifacts, :PkgArtifacts)
                Base.depwarn("using Pkg instead of using LazyArtifacts is deprecated", :var"@artifact_str", force=true)
            end
            path_base = @invokelatest LazyArtifacts.ensure_artifact_installed(string(name), meta, artifacts_toml; platform)
            return jointail(path_base, path_tail)
        end
        error("Artifact $(repr(name)) is a lazy artifact; package developers must call `using LazyArtifacts` in $(__module__) before using lazy artifacts.")
    end

    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 if the artifact is part of a package \
         or call `Pkg.ensure_artifact_installed` (https://pkgdocs.julialang.org/v1/api/#Pkg.Artifacts.ensure_artifact_installed) if not."
    end

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

raw"""
    split_artifact_slash(name::String)

Splits an artifact indexing string by path delimiters, isolates the first path element,

Review comment (suggestion):
```suggestion
            path_base = (@invokelatest LazyArtifacts.ensure_artifact_installed(string(name), meta, artifacts_toml; platform))::String
```

Code after:
end

function __artifact_str(__module__, artifacts_toml, name, path_tail, artifact_dict, hash, platform, ::Val{LazyArtifacts}) where LazyArtifacts
    pkg = Base.PkgId(__module__)
    if pkg.uuid !== nothing
        # Process overrides for this UUID, if we know what it is
        process_overrides(artifact_dict, pkg.uuid)
    end

    # If the artifact exists, we're in the happy path and we can immediately
    # return the path to the artifact:
    dirs = artifact_paths(hash; honor_overrides=true)
    for dir in dirs
        if isdir(dir)
            return jointail(dir, path_tail)
        end
    end

    # If not, try determining what went wrong:
    meta = artifact_meta(name, artifact_dict, artifacts_toml; platform)
    if meta !== nothing && get(meta, "lazy", false)
        if LazyArtifacts isa Module && isdefined(LazyArtifacts, :ensure_artifact_installed)
            if nameof(LazyArtifacts) in (:Pkg, :Artifacts, :PkgArtifacts)
                Base.depwarn("using Pkg instead of using LazyArtifacts is deprecated", :var"@artifact_str", force=true)
            end
            path_base = (@invokelatest LazyArtifacts.ensure_artifact_installed(string(name), meta, artifacts_toml; platform))::String
            return jointail(path_base, path_tail)
        end
        error("Artifact $(repr(name)) is a lazy artifact; package developers must call `using LazyArtifacts` in $(__module__) before using lazy artifacts.")
    end

    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 if the artifact is part of a package \
         or call `Pkg.ensure_artifact_installed` (https://pkgdocs.julialang.org/v1/api/#Pkg.Artifacts.ensure_artifact_installed) if not."
    end

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

raw"""
    split_artifact_slash(name::String)

Splits an artifact indexing string by path delimiters, isolates the first path element,