@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fail in a more comprehensible way when a WorkingCopy lease omits or mangles "repositories.map"

Summary: Ref T13676. When the required "repositories.map" attribute is omitted, `bin/drydock lease` currently fatals in an unhelpful way when trying to lease a working copy.

Test Plan:
Ran `bin/drydock lease --type working-copy` with no attributes, after following steps in T13676.

```
<Allocation Failed> One or more blueprints promised a new resource, but failed when allocating: [PhutilAggregateException] All blueprints failed to allocate a suitable new resource when trying to allocate lease ("PHID-DRYL-orbtwtlinksm3xqpyhmw").
- Exception: Working copy lease is missing required attribute "repositories.map".

Attribute "repositories.map" should be a map of repository specifications.
```

Subscribers: yelirekim, PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13676

Differential Revision: https://secure.phabricator.com/D21796

+39 -8
+39 -8
src/applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php
··· 135 135 ->setAllowedBlueprintPHIDs($blueprint_phids); 136 136 $resource->setAttribute('host.leasePHID', $host_lease->getPHID()); 137 137 138 - $map = $lease->getAttribute('repositories.map'); 139 - foreach ($map as $key => $value) { 140 - $map[$key] = array_select_keys( 141 - $value, 142 - array( 143 - 'phid', 144 - )); 145 - } 138 + $map = $this->getWorkingCopyRepositoryMap($lease); 146 139 $resource->setAttribute('repositories.map', $map); 147 140 148 141 $slot_lock = $this->getConcurrentResourceLimitSlotLock($blueprint); ··· 155 148 $host_lease->queueForActivation(); 156 149 157 150 return $resource; 151 + } 152 + 153 + private function getWorkingCopyRepositoryMap(DrydockLease $lease) { 154 + $attribute = 'repositories.map'; 155 + $map = $lease->getAttribute($attribute); 156 + 157 + // TODO: Leases should validate their attributes more formally. 158 + 159 + if (!is_array($map) || !$map) { 160 + $message = array(); 161 + if ($map === null) { 162 + $message[] = pht( 163 + 'Working copy lease is missing required attribute "%s".', 164 + $attribute); 165 + } else { 166 + $message[] = pht( 167 + 'Working copy lease has invalid attribute "%s".', 168 + $attribute); 169 + } 170 + 171 + $message[] = pht( 172 + 'Attribute "repositories.map" should be a map of repository '. 173 + 'specifications.'); 174 + 175 + $message = implode("\n\n", $message); 176 + 177 + throw new Exception($message); 178 + } 179 + 180 + foreach ($map as $key => $value) { 181 + $map[$key] = array_select_keys( 182 + $value, 183 + array( 184 + 'phid', 185 + )); 186 + } 187 + 188 + return $map; 158 189 } 159 190 160 191 public function activateResource(