A natural approach to sorting an outline recursively would be the following:
(org-map-entries (lambda ()
(org-sort-entries nil ?f 'my/sort-function)
nil 'tree)
This doesn't work; it stops after sorting the top-level heading because org-sort-entries
throws an error on any leaf node:
user-error: Nothing to sort
Do any alternatives exist?