Skip to content

Pkg.test(force_latest_compatible_version=true) errors with unregistered dependencies trying to reduce over an empty collection #3684

@anowacki

Description

@anowacki

If a project contains unregistered dependencies and is tested with Pkg.test(force_latest_compatible_version=true), an error is thrown in the call to maximum at

latest_compatible_version = maximum(compatible_versions)
because the vector compatible_versions is empty.

This gives you a stacktrace like below. Should this case be tested for and a more helpful error be thrown instead?

     Testing Tester
ERROR: LoadError: MethodError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer
Stacktrace:
  [1] reduce_empty(op::Base.BottomRF{typeof(max)}, #unused#::Type{VersionNumber})
    @ Base ./reduce.jl:355
  [2] reduce_empty_iter
    @ ./reduce.jl:379 [inlined]
  [3] reduce_empty_iter
    @ ./reduce.jl:378 [inlined]
  [4] foldl_impl
    @ ./reduce.jl:49 [inlined]
  [5] mapfoldl_impl
    @ ./reduce.jl:44 [inlined]
  [6] #mapfoldl#288
    @ ./reduce.jl:170 [inlined]
  [7] mapfoldl
    @ ./reduce.jl:170 [inlined]
  [8] #mapreduce#292
    @ ./reduce.jl:302 [inlined]
  [9] mapreduce
    @ ./reduce.jl:302 [inlined]
 [10] #maximum#302
    @ ./reduce.jl:759 [inlined]
 [11] maximum
    @ ./reduce.jl:759 [inlined]
 [12] get_latest_compatible_version
    @ /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/Operations.jl:2596 [inlined]
 [13] apply_force_latest_compatible_version!(ctx::Pkg.Types.Context, dep::NamedTuple{(:name, :uuid), Tuple{String, Base.UUID}}; target_name::String, allow_earlier_backwards_compatible_versions::Bool)
    @ Pkg.Operations /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/Operations.jl:2564
 [14] apply_force_latest_compatible_version!
    @ /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/Operations.jl:2548 [inlined]
 [15] apply_force_latest_compatible_version!(ctx::Pkg.Types.Context; target_name::String, allow_earlier_backwards_compatible_versions::Bool)
    @ Pkg.Operations /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/Operations.jl:2537
 [16] apply_force_latest_compatible_version!
    @ /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/Operations.jl:2530 [inlined]
 [17] (::Pkg.Operations.var"#117#122"{String, Bool, Bool, Bool, Pkg.Operations.var"#130#134"{Bool, Cmd, Cmd, Nothing, Pkg.Types.Context, Vector{Tuple{String, Base.Process}}, String, Pkg.Types.PackageSpec}, Pkg.Types.PackageSpec})()
    @ Pkg.Operations /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/Operations.jl:1795
 [18] with_temp_env(fn::Pkg.Operations.var"#117#122"{String, Bool, Bool, Bool, Pkg.Operations.var"#130#134"{Bool, Cmd, Cmd, Nothing, Pkg.Types.Context, Vector{Tuple{String, Base.Process}}, String, Pkg.Types.PackageSpec}, Pkg.Types.PackageSpec}, temp_env::String)
    @ Pkg.Operations /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/Operations.jl:1701
 [19] (::Pkg.Operations.var"#115#120"{Dict{String, Any}, Bool, Bool, Bool, Pkg.Operations.var"#130#134"{Bool, Cmd, Cmd, Nothing, Pkg.Types.Context, Vector{Tuple{String, Base.Process}}, String, Pkg.Types.PackageSpec}, Pkg.Types.Context, Pkg.Types.PackageSpec, String, Pkg.Types.Project, String})(tmp::String)
    @ Pkg.Operations /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/Operations.jl:1790
 [20] mktempdir(fn::Pkg.Operations.var"#115#120"{Dict{String, Any}, Bool, Bool, Bool, Pkg.Operations.var"#130#134"{Bool, Cmd, Cmd, Nothing, Pkg.Types.Context, Vector{Tuple{String, Base.Process}}, String, Pkg.Types.PackageSpec}, Pkg.Types.Context, Pkg.Types.PackageSpec, String, Pkg.Types.Project, String}, parent::String; prefix::String)
    @ Base.Filesystem ./file.jl:760
 [21] mktempdir(fn::Function, parent::String)
    @ Base.Filesystem ./file.jl:756
 [22] mktempdir
    @ ./file.jl:756 [inlined]
 [23] sandbox(fn::Function, ctx::Pkg.Types.Context, target::Pkg.Types.PackageSpec, target_path::String, sandbox_path::String, sandbox_project_override::Pkg.Types.Project; preferences::Dict{String, Any}, force_latest_compatible_version::Bool, allow_earlier_backwards_compatible_versions::Bool, allow_reresolve::Bool)
    @ Pkg.Operations /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/Operations.jl:1748
 [24] test(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; coverage::Bool, julia_args::Cmd, test_args::Cmd, test_fn::Nothing, force_latest_compatible_version::Bool, allow_earlier_backwards_compatible_versions::Bool, allow_reresolve::Bool)
    @ Pkg.Operations /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/Operations.jl:1958
 [25] test
    @ /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/Operations.jl:1902 [inlined]
 [26] test(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; coverage::Bool, test_fn::Nothing, julia_args::Cmd, test_args::Cmd, force_latest_compatible_version::Bool, allow_earlier_backwards_compatible_versions::Bool, allow_reresolve::Bool, kwargs::Base.Pairs{Symbol, Base.TTY, Tuple{Symbol}, NamedTuple{(:io,), Tuple{Base.TTY}}})
    @ Pkg.API /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/API.jl:441
 [27] test(pkgs::Vector{Pkg.Types.PackageSpec}; io::Base.TTY, kwargs::Base.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:force_latest_compatible_version,), Tuple{Bool}}})
    @ Pkg.API /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/API.jl:156
 [28] test(; name::Nothing, uuid::Nothing, version::Nothing, url::Nothing, rev::Nothing, path::Nothing, mode::Pkg.Types.PackageMode, subdir::Nothing, kwargs::Base.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:force_latest_compatible_version,), Tuple{Bool}}})
    @ Pkg.API /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/API.jl:171
 [29] top-level scope
    @ /private/tmp/Tester/bin/mwe.jl:4
in expression starting at /private/tmp/Tester/bin/mwe.jl:4

This came up for me when testing a CompatHelper pull request, and only on Julia v1.9: https://github.com/anowacki/Beamforming.jl/actions/runs/6746373999/job/18340164600?pr=3.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions