The way SetOfVec::insert is implemented results in the internal structure containing an unsorted duplicate value, because it first inserts the value, and then check whether it's a dupe while simultaneously sorting it:
Could der_sort perhaps remove the duplicate so the structure is still valid in case the insert function returns an error?