@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.

Config page: add lovely git-related error messages in standard error log

Summary:
Premise: the Config page runs git commands. Spoiler: they can fail.

Before this change errors were just suppressed and ignored.

After this change you get at least a log line. Also, you get a tip for a very specific well-known error affecting recent git.

Probably suppressing stuff was fine in the moment git worked here. But nowadays
git doesn't work so easily here, since it introduced very weird additional
configurations in order for a repository to be indicated as "safe" or not.

Error suppression was a problem there, because understanding the error with
"future objects" is not trivial for most users. Really.

After this change, these errors are beautifully mentioned in the standard log
of your webserver, to the best of our communication ability.

This is a cute example of a new log line:

Cannot identify the version of the phorge repository because the webserver does not trust it (more info on Task https://we.phorge.it/T15282).
Try this system resolution:
sudo git config --system --add safe.directory /var/www/phorge

Another:

Cannot identify the version of the phorge repository because the webserver does not trust it (more info on Task https://we.phorge.it/T15282).
Try this system resolution:
sudo git config --system --add safe.directory /var/www/arcanist

Incidentally, these specific errors probably afflict your Phorge/Phabricator, and now
you have some useful resolution tips. You are welcome!

You can also join T15282 to discuss your specific case.

Closes T15243

Test Plan:
- visit the `/config/` page: does it worked before? it still works now
- visit the `/config/` page without `/etc/gitconfig`: you may still see "Unknown" as version - but, you finally get something in the log (instead of nothing)
- visit the `/config/` page after following your log messages: now you should see the library versions! yeeh

Additional tests:

- manually sabotage the command "git log" replacing with "gitfooolog" and visit /config page: see the unexpected 'gitfooolog command not found' log line
- manually sabotage the command "git remove" replacing with "gitremotelog" and visit /config/ page: see the unexpected 'gitremotelog command not found' log line

Reviewers: O1 Blessed Committers, avivey

Reviewed By: O1 Blessed Committers, avivey

Subscribers: avivey, deadalnix, aklapper, speck, tobiaswiese, Matthew, Cigaryno

Maniphest Tasks: T15243

Differential Revision: https://we.phorge.it/D25148

+41 -8
+41 -8
src/applications/config/controller/PhabricatorConfigConsoleController.php
··· 189 189 foreach ($specs as $lib) { 190 190 $remote_future = $remote_futures[$lib]; 191 191 192 - list($err, $stdout) = $remote_future->resolve(); 193 - if ($err) { 194 - // If this fails for whatever reason, just move on. 192 + try { 193 + list($stdout, $err) = $remote_future->resolvex(); 194 + } catch (CommandException $e) { 195 + $this->logGitErrorWithPotentialTips($e, $lib); 195 196 continue; 196 197 } 197 198 ··· 258 259 259 260 $results = array(); 260 261 foreach ($log_futures as $lib => $future) { 261 - list($err, $stdout) = $future->resolve(); 262 - if (!$err) { 262 + try { 263 + list($stdout, $err) = $future->resolvex(); 263 264 list($hash, $epoch) = explode(' ', $stdout); 264 - } else { 265 + } catch (CommandException $e) { 265 266 $hash = null; 266 267 $epoch = null; 267 - } 268 + $this->logGitErrorWithPotentialTips($e, $lib); 269 + } 268 270 269 271 $result = array( 270 272 'hash' => $hash, ··· 275 277 276 278 $upstream_future = idx($upstream_futures, $lib); 277 279 if ($upstream_future) { 278 - list($err, $stdout) = $upstream_future->resolve(); 280 + list($stdout, $err) = $upstream_future->resolvex(); 279 281 if (!$err) { 280 282 $branchpoint = trim($stdout); 281 283 if (strlen($branchpoint)) { ··· 340 342 ->appendChild($table_view); 341 343 } 342 344 345 + /** 346 + * Help in better troubleshooting git errors. 347 + * @param CommandException $e Exception 348 + * @param string $lib Library name involved 349 + */ 350 + private function logGitErrorWithPotentialTips($e, $lib) { 351 + 352 + // First, detect this specific error message related to [safe] stuff. 353 + $expected_error_msg_part = 'detected dubious ownership in repository'; 354 + $stderr = $e->getStderr(); 355 + if (strpos($stderr, $expected_error_msg_part) !== false) { 356 + 357 + // Found! Let's show a nice resolution tip. 358 + 359 + // Complete path of the problematic repository. 360 + $lib_root = dirname(phutil_get_library_root($lib)); 361 + 362 + phlog(pht( 363 + "Cannot identify the version of the %s repository because ". 364 + "the webserver does not trust it (more info on Task %s).\n". 365 + "Try this system resolution:\n". 366 + "sudo git config --system --add safe.directory %s", 367 + $lib, 368 + 'https://we.phorge.it/T15282', 369 + $lib_root)); 370 + } else { 371 + 372 + // Otherwise show a generic error message 373 + phlog($e); 374 + } 375 + } 343 376 344 377 }