Skip to content

Commit 9ce1271

Browse files
author
epriestley
committedJun 16, 2020
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
1 parent 8c7f114 commit 9ce1271

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed
 

‎scripts/ssh/ssh-exec.php

+36-15
Original file line numberDiff line numberDiff line change
@@ -211,21 +211,29 @@
211211
->setUniqueMethod('getName')
212212
->execute();
213213

214+
$command_list = array_keys($workflows);
215+
$command_list = implode(', ', $command_list);
216+
217+
$error_lines = array();
218+
$error_lines[] = pht('Welcome to Phabricator.');
219+
$error_lines[] = pht(
220+
'You are logged in as %s.',
221+
$user_name);
222+
214223
if (!$original_argv) {
215-
throw new Exception(
216-
pht(
217-
"Welcome to Phabricator.\n\n".
218-
"You are logged in as %s.\n\n".
219-
"You haven't specified a command to run. This means you're requesting ".
220-
"an interactive shell, but Phabricator does not provide an ".
221-
"interactive shell over SSH.\n\n".
222-
"Usually, you should run a command like `%s` or `%s` ".
223-
"rather than connecting directly with SSH.\n\n".
224-
"Supported commands are: %s.",
225-
$user_name,
226-
'git clone',
227-
'hg push',
228-
implode(', ', array_keys($workflows))));
224+
$error_lines[] = pht(
225+
'You have not specified a command to run. This means you are requesting '.
226+
'an interactive shell, but Phabricator does not provide interactive '.
227+
'shells over SSH.');
228+
$error_lines[] = pht(
229+
'(Usually, you should run a command like "git clone" or "hg push" '.
230+
'instead of connecting directly with SSH.)');
231+
$error_lines[] = pht(
232+
'Supported commands are: %s.',
233+
$command_list);
234+
235+
$error_lines = implode("\n\n", $error_lines);
236+
throw new PhutilArgumentUsageException($error_lines);
229237
}
230238

231239
$log_argv = implode(' ', $original_argv);
@@ -247,7 +255,20 @@
247255
$parsed_args = new PhutilArgumentParser($parseable_argv);
248256

249257
if (empty($workflows[$command])) {
250-
throw new Exception(pht('Invalid command.'));
258+
$error_lines[] = pht(
259+
'You have specified the command "%s", but that command is not '.
260+
'supported by Phabricator. As received by Phabricator, your entire '.
261+
'argument list was:',
262+
$command);
263+
264+
$error_lines[] = csprintf(' $ ssh ... -- %Ls', $parseable_argv);
265+
266+
$error_lines[] = pht(
267+
'Supported commands are: %s.',
268+
$command_list);
269+
270+
$error_lines = implode("\n\n", $error_lines);
271+
throw new PhutilArgumentUsageException($error_lines);
251272
}
252273

253274
$workflow = $parsed_args->parseWorkflows($workflows);

0 commit comments

Comments
 (0)
Failed to load comments.