diff --git a/lib/src/ssh_client.dart b/lib/src/ssh_client.dart index ee841f5..fb33181 100644 --- a/lib/src/ssh_client.dart +++ b/lib/src/ssh_client.dart @@ -170,8 +170,8 @@ class SSHClient { ); _transport.done.then( - (_) => _handleTransportClosed(), - onError: (_) => _handleTransportClosed(), + (_) => _handleTransportClosed(null), + onError: (e) => _handleTransportClosed(e), ); _authenticated.future.catchError( @@ -473,11 +473,12 @@ class SSHClient { _requestAuthentication(); } - void _handleTransportClosed() { + + void _handleTransportClosed(SSHError? error) { printDebug?.call('SSHClient._onTransportClosed'); if (!_authenticated.isCompleted) { _authenticated.completeError( - SSHAuthAbortError('Connection closed before authentication'), + SSHAuthAbortError('Connection closed before authentication', error) ); } _keepAlive?.stop(); diff --git a/lib/src/ssh_errors.dart b/lib/src/ssh_errors.dart index 68407de..11c6c94 100644 --- a/lib/src/ssh_errors.dart +++ b/lib/src/ssh_errors.dart @@ -50,7 +50,9 @@ class SSHAuthAbortError with SSHMessageError implements SSHAuthError { @override final String message; - SSHAuthAbortError(this.message); + final SSHError? reason; + + SSHAuthAbortError(this.message, this.reason); } /// Errors that happen when the library receives an malformed packet. diff --git a/test/src/ssh_client_test.dart b/test/src/ssh_client_test.dart index ecd9189..38171da 100644 --- a/test/src/ssh_client_test.dart +++ b/test/src/ssh_client_test.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:dartssh2/dartssh2.dart'; import 'package:test/test.dart'; @@ -137,6 +139,7 @@ void main() { fail('should have thrown'); } catch (e) { expect(e, isA()); + expect((e as SSHAuthAbortError).reason!, isA()); } client.close();