@@ -12,7 +12,6 @@ import com.intellij.remote.RemoteConnector
12
12
import com.intellij.remote.RemoteCredentials
13
13
import com.intellij.ssh.ConnectionBuilder
14
14
import com.intellij.ssh.ExecBuilder
15
- import com.intellij.ssh.SshException
16
15
import com.intellij.ssh.channels.SftpChannel
17
16
import com.intellij.ssh.connectionBuilder
18
17
import com.jetbrains.plugins.remotesdk.console.SshConfigConnector
@@ -24,9 +23,12 @@ import com.vk.admstorm.transfer.TransferService
24
23
import com.vk.admstorm.utils.MySshUtils
25
24
import com.vk.admstorm.utils.MyUtils.executeOnPooledThread
26
25
import git4idea.util.GitUIUtil.code
26
+ import net.schmizz.sshj.connection.channel.OpenFailException
27
27
import net.schmizz.sshj.sftp.SFTPClient
28
+ import net.schmizz.sshj.transport.TransportException
28
29
import java.io.IOException
29
30
import java.util.concurrent.TimeUnit
31
+ import java.util.concurrent.TimeoutException
30
32
31
33
/* *
32
34
* Service responsible for connecting via SSH to the development server.
@@ -144,26 +146,16 @@ class SshConnectionService(private var myProject: Project) : Disposable {
144
146
145
147
override fun run (indicator : ProgressIndicator ) {
146
148
try {
147
- mySftpChannel = myConnectionBuilder!! .openSftpChannel(2 )
148
- mySftpClient = MySshUtils .getSftpClient(mySftpChannel!! )
149
+ SshHandler .handle {
150
+ mySftpChannel = myConnectionBuilder!! .openSftpChannel(2 )
151
+ mySftpClient = MySshUtils .getSftpClient(mySftpChannel!! )
149
152
150
- onSuccessful?.run ()
151
- } catch (e: SshException ) {
152
- if (! cancelled && e.message == " Cancelled by user" ) {
153
- LOG .warn(" Cancelled by user" , e)
154
- return
153
+ onSuccessful?.run ()
155
154
}
156
-
157
- val exceptionMessage = e.message
158
- ?.removePrefix(" java.net.SocketTimeoutException: " )
159
- ?.replaceFirstChar { it.uppercaseChar() }
160
- ?.plus(" <br>" )
161
- ? : " "
162
-
163
- val message =
164
- " ${exceptionMessage} Plugin can try to automatically reset the Yubikey or you can do it yourself with ${
155
+ } catch (ex: OpenFailException ) {
156
+ val message = " ${ex.message} <br>" +
157
+ " Plugin can try to automatically reset the Yubikey or you can do it yourself with " +
165
158
code(" ssh-agent" )
166
- } "
167
159
168
160
AdmErrorNotification (message, true )
169
161
.withTitle(" Failed to connect to server" )
@@ -185,7 +177,50 @@ class SshConnectionService(private var myProject: Project) : Disposable {
185
177
})
186
178
.show()
187
179
188
- LOG .warn(" Failed to connect" , e)
180
+ LOG .warn(" Failed to connect" , ex)
181
+ } catch (ex: TimeoutException ) {
182
+ if (indicator.isCanceled) {
183
+ LOG .info(" Cancelled by user" , ex)
184
+ return
185
+ }
186
+
187
+ AdmNotification (" Touch the yubikey when it blinks while using AdmStorm" )
188
+ .withTitle(" Yubikey waiting timeout" )
189
+ .withActions(AdmNotification .Action (" Reconnect..." ) { _, notification ->
190
+ notification.expire()
191
+ connectWithConnector(connector, onSuccessful)
192
+ }).show()
193
+
194
+ LOG .info(" Yubikey waiting timeout" , ex)
195
+ } catch (ex: TransportException ) {
196
+ if (ex.message == null ) {
197
+ LOG .error(" Transport exception:" , ex.javaClass.name)
198
+ return
199
+ }
200
+
201
+ if (ex.message?.contains(" HostKeyAlgorithms" ) == true ) {
202
+ AdmErrorNotification (" Recheck your config or the documentation" , true )
203
+ .withTitle(" Did you add HostKeyAlgorithms to your config?" )
204
+ .withActions(AdmNotification .Action (" Reconnect..." ) { _, notification ->
205
+ notification.expire()
206
+ connectWithConnector(connector, onSuccessful)
207
+ }).show()
208
+ LOG .info(" Not correct ssh config type" , ex)
209
+ return
210
+ }
211
+
212
+ AdmErrorNotification (" Check the documentation about connection to network" , true )
213
+ .withTitle(" Did you miss your connection?" )
214
+ .withActions(AdmNotification .Action (" Reconnect..." ) { _, notification ->
215
+ notification.expire()
216
+ connectWithConnector(connector, onSuccessful)
217
+ }).show()
218
+ LOG .info(" Corporate access error" , ex)
219
+ } catch (ex: Exception ) {
220
+ val exceptionName = ex.javaClass.name
221
+ LOG .error(" Unhandled exception" , ex)
222
+ AdmErrorNotification (" Unhandled exception $exceptionName " ).show()
223
+ return
189
224
}
190
225
}
191
226
0 commit comments