Skip to content

Prevent `MultipleExceptionError#add` from allowing self to be added to the list of `all_exceptions`

Created by: penelopezone

This was exposed by https://github.com/rspec/rspec-core/pull/2112 which contains a spec which uses describe_successfully which seems to somehow add the existing MultipleExceptionError to itself when it fails. This does not happen if the example passes (presumably because an error is not generated).

When we format the exception here we use FlatMap, which is going to continuously unpack the exception, causing infinite recursion.

This patch prevents MultipleExceptionError::InterfaceTag#add from allowing self to be included in the all_exceptions array. This fixes the problem.

As far as I can tell from running our suite, the self being added case never actually happens during normal RSpec execution and so adding this is fine. I added a spec which demonstrates this behaviour in case that turns out to be problematic in the future. I can't imagine that happening though as this will precisely cause the same infinite recursion bug.

Merge request reports