fix: report direct ssh login failures

This commit is contained in:
Marek Miklewicz
2026-06-30 15:42:18 +02:00
parent c115b2861d
commit 42afc5853c
4 changed files with 41 additions and 3 deletions
+19 -1
View File
@@ -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
*/