mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 16:22:43 +01:00
Improve the quality of SSH error messages
Summary: See PHI1784. Currently, users who pass an invalid SSH command to Phabricator's SSH handler get an unhelpful error message. Make it more helpful. Test Plan: Ran `./bin/ssh-exec` with no arguments (old, helpful error), invalid arguments (before: unhelpful error; after: helpful error), and valid arguments (old, helpful behavior). Differential Revision: https://secure.phabricator.com/D21362
This commit is contained in:
parent
8c7f114b4d
commit
9ce1271805
1 changed files with 36 additions and 15 deletions
|
@ -211,21 +211,29 @@ try {
|
||||||
->setUniqueMethod('getName')
|
->setUniqueMethod('getName')
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
|
$command_list = array_keys($workflows);
|
||||||
|
$command_list = implode(', ', $command_list);
|
||||||
|
|
||||||
|
$error_lines = array();
|
||||||
|
$error_lines[] = pht('Welcome to Phabricator.');
|
||||||
|
$error_lines[] = pht(
|
||||||
|
'You are logged in as %s.',
|
||||||
|
$user_name);
|
||||||
|
|
||||||
if (!$original_argv) {
|
if (!$original_argv) {
|
||||||
throw new Exception(
|
$error_lines[] = pht(
|
||||||
pht(
|
'You have not specified a command to run. This means you are requesting '.
|
||||||
"Welcome to Phabricator.\n\n".
|
'an interactive shell, but Phabricator does not provide interactive '.
|
||||||
"You are logged in as %s.\n\n".
|
'shells over SSH.');
|
||||||
"You haven't specified a command to run. This means you're requesting ".
|
$error_lines[] = pht(
|
||||||
"an interactive shell, but Phabricator does not provide an ".
|
'(Usually, you should run a command like "git clone" or "hg push" '.
|
||||||
"interactive shell over SSH.\n\n".
|
'instead of connecting directly with SSH.)');
|
||||||
"Usually, you should run a command like `%s` or `%s` ".
|
$error_lines[] = pht(
|
||||||
"rather than connecting directly with SSH.\n\n".
|
'Supported commands are: %s.',
|
||||||
"Supported commands are: %s.",
|
$command_list);
|
||||||
$user_name,
|
|
||||||
'git clone',
|
$error_lines = implode("\n\n", $error_lines);
|
||||||
'hg push',
|
throw new PhutilArgumentUsageException($error_lines);
|
||||||
implode(', ', array_keys($workflows))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$log_argv = implode(' ', $original_argv);
|
$log_argv = implode(' ', $original_argv);
|
||||||
|
@ -247,7 +255,20 @@ try {
|
||||||
$parsed_args = new PhutilArgumentParser($parseable_argv);
|
$parsed_args = new PhutilArgumentParser($parseable_argv);
|
||||||
|
|
||||||
if (empty($workflows[$command])) {
|
if (empty($workflows[$command])) {
|
||||||
throw new Exception(pht('Invalid command.'));
|
$error_lines[] = pht(
|
||||||
|
'You have specified the command "%s", but that command is not '.
|
||||||
|
'supported by Phabricator. As received by Phabricator, your entire '.
|
||||||
|
'argument list was:',
|
||||||
|
$command);
|
||||||
|
|
||||||
|
$error_lines[] = csprintf(' $ ssh ... -- %Ls', $parseable_argv);
|
||||||
|
|
||||||
|
$error_lines[] = pht(
|
||||||
|
'Supported commands are: %s.',
|
||||||
|
$command_list);
|
||||||
|
|
||||||
|
$error_lines = implode("\n\n", $error_lines);
|
||||||
|
throw new PhutilArgumentUsageException($error_lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
$workflow = $parsed_args->parseWorkflows($workflows);
|
$workflow = $parsed_args->parseWorkflows($workflows);
|
||||||
|
|
Loading…
Reference in a new issue