class Bundler::PubGrub::Incompatibility

def to_s

def to_s
  return @custom_explanation if @custom_explanation
  case cause
  when :root
    "(root dependency)"
  when :dependency
    "#{terms[0].to_s(allow_every: true)} depends on #{terms[1].invert}"
  when Bundler::PubGrub::Incompatibility::InvalidDependency
    "#{terms[0].to_s(allow_every: true)} depends on unknown package #{cause.package}"
  when Bundler::PubGrub::Incompatibility::NoVersions
    "no versions satisfy #{cause.constraint}"
  when Bundler::PubGrub::Incompatibility::ConflictCause
    if failure?
      "version solving has failed"
    elsif terms.length == 1
      term = terms[0]
      if term.positive?
        if term.constraint.any?
          "#{term.package} cannot be used"
        else
          "#{term.to_s(allow_every: true)} cannot be used"
        end
      else
        "#{term.invert} is required"
      end
    else
      if terms.all?(&:positive?)
        if terms.length == 2
          "#{terms[0].to_s(allow_every: true)} is incompatible with #{terms[1]}"
        else
          "one of #{terms.map(&:to_s).join(" or ")} must be false"
        end
      elsif terms.all?(&:negative?)
        if terms.length == 2
          "either #{terms[0].invert} or #{terms[1].invert}"
        else
          "one of #{terms.map(&:invert).join(" or ")} must be true";
        end
      else
        positive = terms.select(&:positive?)
        negative = terms.select(&:negative?).map(&:invert)
        if positive.length == 1
          "#{positive[0].to_s(allow_every: true)} requires #{negative.join(" or ")}"
        else
          "if #{positive.join(" and ")} then #{negative.join(" or ")}"
        end
      end
    end
  else
    raise "unhandled cause: #{cause.inspect}"
  end
end