doctor: don't pass pathnames to Formula.factory

Fixes #20908.