Skip to content

Plotting graph without edges causes an uncaught error in Base #5196

@nimaser

Description

@nimaser

The error occurs when calculating some details about the layout. This line calls this one, which is where the error drops into Base.

Steps to reproduce on Julia Version 1.12.1 (2025-10-17) with GraphRecipes v0.5.15:

using GraphRecipes, Plots
using Graphs
g = Graph()
graphplot(g) # error whose stack trace is displayed below

Having vertices but no edges still causes a problem:

using GraphRecipes, Plots
using Graphs
g = Graph()
add_vertices!(g, 2)
graphplot(g) # error

Only after adding an edge does the plot get generated and displayed properly:

using GraphRecipes, Plots
using Graphs
g = Graph()
add_vertices!(g, 2)
add_edge!(g, 1, 2)
graphplot(g) # no problems

Output of the first case in the REPL:

ERROR: ArgumentError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer
Stacktrace:
  [1] _empty_reduce_error()
    @ Base ./reduce.jl:311
  [2] reduce_empty(f::Function, T::Type)
    @ Base ./reduce.jl:312
  [3] mapreduce_empty(::typeof(identity), op::Function, T::Type)
    @ Base ./reduce.jl:361
  [4] reduce_empty(op::Base.MappingRF{typeof(identity), typeof(max)}, ::Type{Int64})
    @ Base ./reduce.jl:350
  [5] reduce_empty_iter
    @ ./reduce.jl:373 [inlined]
  [6] mapreduce_empty_iter(f::Function, op::Function, itr::Vector{Int64}, ItrEltype::Base.HasEltype)
    @ Base ./reduce.jl:369
  [7] _mapreduce
    @ ./reduce.jl:421 [inlined]
  [8] _mapreduce_dim
    @ ./reducedim.jl:334 [inlined]
  [9] mapreduce
    @ ./reducedim.jl:326 [inlined]
 [10] _maximum
    @ ./reducedim.jl:984 [inlined]
 [11] _maximum
    @ ./reducedim.jl:983 [inlined]
 [12] maximum
    @ ./reducedim.jl:979 [inlined]
 [13] _broadcast_getindex_evalf
    @ ./broadcast.jl:699 [inlined]
 [14] _broadcast_getindex
    @ ./broadcast.jl:672 [inlined]
 [15] #copy##0
    @ ./broadcast.jl:1124 [inlined]
 [16] ntuple(f::Base.Broadcast.var"#copy##0#copy##1"{Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(maximum), Tuple{Tuple{Vector{Int64}, Vector{Int64}}}}}, ::Val{2})
    @ Base ./ntuple.jl:51
 [17] copy
    @ ./broadcast.jl:1124 [inlined]
 [18] materialize
    @ ./broadcast.jl:894 [inlined]
 [19] infer_size_from(::Vector{Int64}, ::Vararg{Vector{Int64}})
    @ GraphRecipes ~/.julia/packages/GraphRecipes/qS4vH/src/graph_layouts.jl:3
 [20] macro expansion
    @ ~/.julia/packages/GraphRecipes/qS4vH/src/graphs.jl:432 [inlined]
 [21] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, g::GraphRecipes.GraphPlot)
    @ GraphRecipes ~/.julia/packages/RecipesBase/BRe07/src/RecipesBase.jl:300
 [22] _process_userrecipes!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/user_recipe.jl:38
 [23] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/RecipesPipeline.jl:72
 [24] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots ~/.julia/packages/Plots/8ZnR3/src/plot.jl:223
 [25] #plot#150
    @ ~/.julia/packages/Plots/8ZnR3/src/plot.jl:102 [inlined]
 [26] plot
    @ ~/.julia/packages/Plots/8ZnR3/src/plot.jl:93 [inlined]
 [27] graphplot(args::SimpleGraph{Int64})
    @ GraphRecipes ~/.julia/packages/RecipesBase/BRe07/src/RecipesBase.jl:380
 [28] top-level scope
    @ REPL[9]:1

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions