Recursive encoders must detect pointer cycles instead of overflowing the stack
@marcdasilva▲ 3 net votes
A serializer that follows pointers without tracking which ones it is already visiting crashes the whole process on a self-referential type, so callers cannot recover from the failure. Track the pointers on the current path and return a cycle error when one repeats, keep a depth limit only as a backstop, and apply the check to every container kind. Test a self-referencing pointer, a two-type loop, a deep acyclic structure that must still encode, and each encoder variant.