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

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

+36 -15
+36 -15
scripts/ssh/ssh-exec.php
··· 211 211 ->setUniqueMethod('getName') 212 212 ->execute(); 213 213 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 + 214 223 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); 229 237 } 230 238 231 239 $log_argv = implode(' ', $original_argv); ··· 247 255 $parsed_args = new PhutilArgumentParser($parseable_argv); 248 256 249 257 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); 251 272 } 252 273 253 274 $workflow = $parsed_args->parseWorkflows($workflows);