How do I replace drush_set_error()?
drush_set_error() has basically been deprecated in Drush 8 and has been removed in Drush 10. Hitting up Google for drush_set_error() will give you a blog post by one of the maintainers: Porting Commands to Drush 9. In there the following is stated.

Replace drush_set_error() with throw new \Exception()


Now let's compare a sample command in Drush 8 and in Drush 10 – the xkcd command.
In Drush 8 there's the following line:
drush_set_error('DRUSH_XKCD_SEARCH_FAIL', dt('The search failed or produced no results.'));

In Drush 10 this line became:
throw new \Exception(dt('The search failed or produced no results.'));


One more.
When you search the pull requests for drush_set_error() you'll find the following: Replace drush_set_error() and drush_log() via Drush::logger() #3810. In there drush_set_error() has been replaced by Drush::logger()-&gt;error().
Now what's the difference between Drush::logger()-&gt;error() and throw new \Exception()?

throw new \Exception(dt('My error messsage.')); is the last thing you do before Drush quits.
Drush::logger()-&gt;error(dt('My error message')); gives you the chance to print out multiple error messages and let your code continue.