The current code has following issues:
- It has a duplicated logic part.
- This logic relies on unwrapOrError calls, but if we want to convert them to warnings, we will need to change all of them what is hard to do because of the duplication.
In this patch I've created a new method that returns Expected<> what allows
now to catch all errors in a single place and remove the code duplication.
Note: this change is itself a refactor NFC. It does not change the current logic
anyhow. It prepares the code for the follow-up(s).