How to diagnose «URL key for specified store already exists»?

Error when trying to save a category
URL key for specified store already exists.

  1. Go to Products - Categories - New:
  2. https://www.pumpunderwear.com/admin/catalog/category/edit/store/17/id/314/
  3. Change something, ie: remove or add a product in the category
  4. Click Save

Error

The «URL key for specified store already exists» message is throws in the following 2-3 places:

1. \Magento\UrlRewrite\Model\Storage\AbstractStorage::replace()

2. \Magento\UrlRewrite\Model\Storage\DbStorage::insertMultiple()

3. \Magento\UrlRewrite\Model\Storage\DbStorage::doReplace()

It is only for the recent Magento 2.2 versions >= 2.2.0-RC1.4.

How to diagnose it

The built-in exception handling of the all these 3 cases is low-quality: it just missed the original exception message and its backtrace.
So to diagnose the exception, log the original exception manually, or set a debugger breakpoint in these 3 code places.