fix: report direct ssh login failures
This commit is contained in:
@@ -96,7 +96,7 @@ final class RemoteLoginUrlClient
|
||||
throw new RuntimeException('Invalid process runner result');
|
||||
}
|
||||
if ($result->exitCode !== 0) {
|
||||
throw new RuntimeException('MX helper failed');
|
||||
throw new RuntimeException(self::failureMessage($settings, $result));
|
||||
}
|
||||
if (!preg_match('/https:\/\/\S+/', $result->stdout, $match)) {
|
||||
throw new RuntimeException('MX helper did not return a login URL');
|
||||
@@ -108,6 +108,24 @@ final class RemoteLoginUrlClient
|
||||
}
|
||||
}
|
||||
|
||||
private static function failureMessage(Settings $settings, ProcessResult $result): string
|
||||
{
|
||||
$message = $settings->mxLoginMode() === 1 ? 'MX direct SSH command failed' : 'MX helper failed';
|
||||
$message .= ' (exit ' . $result->exitCode . ')';
|
||||
$detail = self::safeDiagnostic($result->stderr);
|
||||
if ($detail !== '') {
|
||||
$message .= ': ' . $detail;
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
|
||||
private static function safeDiagnostic(string $text): string
|
||||
{
|
||||
$text = preg_replace('/https?:\/\/\S+/i', '[redacted-url]', $text) ?? '';
|
||||
$text = preg_replace('/\s+/', ' ', trim($text)) ?? '';
|
||||
return substr($text, 0, 512);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $command
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user