diff --git a/src/spaces/graph.jl b/src/spaces/graph.jl index 2f85ecac3..8a96458c1 100644 --- a/src/spaces/graph.jl +++ b/src/spaces/graph.jl @@ -68,8 +68,10 @@ random_position(model::ABM{<:GraphSpace}) = rand(abmrng(model), 1:nv(model)) function remove_agent_from_space!(agent::AbstractAgent, model::ABM{<:GraphSpace}) agentpos = agent.pos ids = ids_in_position(agentpos, model) - deleteat!(ids, findfirst(a -> a == agent.id, ids)) - return model + agentid = findfirst(a -> a == agent.id, ids) + isnothing(agentid) && error(lazy"Tried to remove $(agent) from the space, but that agent is not on the space") + deleteat!(ids, agentid) + return agent end function add_agent_to_space!(agent::AbstractAgent, model::ABM{<:GraphSpace})