this error occurs after upgrading to drupal 9.

You have requested a non-existent service "path.alias_manager"

Solution

Change lines like

$current_alias = \Drupal::service('path.alias_manager')->getAliasByPath($current_path);

to:

$current_alias = \Drupal::service('path_alias.manager')->getAliasByPath($current_path);