I have some code which tends to hand without exiting or responding a lot of the time it's run (the code path it takes is random), and upon Ctrl-C'ing it or similar, I tend to find the top of the stacktrace looks like this:
The code in question here is:
"""
cityindexunchecked(world, id)
Get the index of a [`City`](@ref) into `world.cities` and `world.graph` from it's `id`.
Returns `nothing` if the city isn't found.
"""
function cityindexunchecked(world, id)
findfirst(c -> c.id == id, world.cities)
end
# Convenience method:"Los Angeles", ["San Francisco", "Chicago", "Mexico City", "Sydney"]),
# integers are not valid ids so we assume c is the index and return it
cityindexunchecked(world, id::Int) = id
cityindexunchecked(world, c::City) = cityindexunchecked(world, c.id)
"""
cityindex(world, city[, error])
Get the index of a [`City`](@ref) into `world.cities` and `world.graph` from it's `id`.
Throws an error if the city isn't found.
Pass the parameter `error` to override the error text.
`id` may either be a [`City`](@ref) object or just some identifying object.
"""
function cityindex(world, c, e = "City $c not found")
i = cityindexunchecked(world, c)
@assert i != nothing e
return i
end
export cityindex
Can this be the result of the potential string comparison in cityindexunchecked
? The type of id
is typically a string.
My first guess would be that the culprit is the$c
in cityindex
Last updated: Oct 02 2023 at 04:34 UTC