I found that deleting the code doesn't report an error, but I don't know if there's a bug.
if (not hasNonFurnaceFurnace) then
--add a useless furnace so the game doesn't complain when we remove them later
local uselessFurnace = table.deepcopy(data.raw["furnace"]["stone-furnace"])
uselessFurnace.name = "useless-furnace"
uselessFurnace.flags = {"hidden"}
uselessFurnace.next_upgrade = nil
data:extend{uselessFurnace}
end