From 9a929508ee9c3688f44c1d92e63c9bf15d47b807 Mon Sep 17 00:00:00 2001
From: Wez Furlong <wez@fb.com>
Date: Thu, 20 Jun 2013 08:49:20 -0700
Subject: [PATCH] unbreak typeaheads for /owners/new

Summary:
D6057 introduced images in the typeahead results, but not all
projects return a valid result.  This silently broke /owners/new because
the exception "Call to a member function loadProfileImageURI() on a non-object"
is swallowed somewhere in the handler.

Test Plan: go to /owners/new and type something in the primary owner field

Reviewers: epriestley, nh, Afaque_Hussain

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D6245
---
 .../PhabricatorTypeaheadCommonDatasourceController.php    | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php b/src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php
index a40aefce39..3346b72423 100644
--- a/src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php
+++ b/src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php
@@ -206,12 +206,16 @@ final class PhabricatorTypeaheadCommonDatasourceController
         ->withStatus(PhabricatorProjectQuery::STATUS_OPEN)
         ->execute();
       foreach ($projs as $proj) {
-        $results[] = id(new PhabricatorTypeaheadResult())
+        $proj_result = id(new PhabricatorTypeaheadResult())
           ->setName($proj->getName())
           ->setDisplayType("Project")
           ->setURI('/project/view/'.$proj->getID().'/')
-          ->setImageURI($proj->loadProfile()->loadProfileImageURI())
           ->setPHID($proj->getPHID());
+        $prof = $proj->loadProfile();
+        if ($prof) {
+          $proj_result->setImageURI($prof->loadProfileImageURI());
+        }
+        $results[] = $proj_result;
       }
     }