Refactor commandForExtension and commandForLanguage so they return errors