This MR change an assert statement to a throw runtime_error. assert might have no effect (depending on compilation options) and this can be very confusing. This is only a better protection and should have no impact for official jobs. (will be ported to rel23/master later)