1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-13 12:05:21 +02:00

[206919][terminal] Improve SSH Terminal Error Reporting

This commit is contained in:
Martin Oberhuber 2008-07-15 23:36:38 +00:00
parent ce78395c37
commit 81e239e15a
3 changed files with 111 additions and 13 deletions

View file

@ -18,6 +18,7 @@
* Martin Oberhuber (Wind River) - [168197] Replace JFace MessagDialog by SWT MessageBox
* Martin Oberhuber (Wind River) - [205674][ssh] Terminal remains "connecting" when authentication is cancelled
* Michael Scharf (Wind River) - 240420: [terminal][ssh]Channel is not closed when the connection is closed with the close button
* Martin Oberhuber (Wind River) - [206919] Improve SSH Terminal Error Reporting
*******************************************************************************/
package org.eclipse.tm.internal.terminal.ssh;
@ -30,6 +31,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jface.window.Window;
import org.eclipse.jsch.core.IJSchService;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
@ -90,13 +92,16 @@ class SshConnection extends Thread {
//----------------------------------------------------------------------
public void run() {
boolean connectSucceeded = false;
String host = ""; //$NON-NLS-1$
int port = 22;
try {
int nTimeout = fConn.getSshSettings().getTimeout() * 1000;
int nKeepalive = fConn.getSshSettings().getKeepalive() * 1000;
String host = fConn.getSshSettings().getHost();
host = fConn.getSshSettings().getHost();
String user = fConn.getSshSettings().getUser();
String password = fConn.getSshSettings().getPassword();
int port = fConn.getSshSettings().getPort();
port = fConn.getSshSettings().getPort();
////Giving a connectionId could be the index into a local
////Store where passwords are stored
@ -136,6 +141,7 @@ class SshConnection extends Thread {
// maybe the terminal was disconnected while we were connecting
if (isSessionConnected() && channel.isConnected()) {
connectSucceeded = true;
fConn.setInputStream(channel.getInputStream());
fConn.setOutputStream(channel.getOutputStream());
fConn.setChannel(channel);
@ -148,7 +154,27 @@ class SshConnection extends Thread {
}
}
} catch (Exception e) {
connectFailed(e.getMessage(),e.getMessage());
Throwable cause = e;
while (cause.getCause() != null) {
cause = cause.getCause();
}
String origMsg = cause.getMessage();
String msg = SshMessages.getMessageFor(cause);
if ((cause instanceof JSchException) && origMsg != null && origMsg.startsWith("Auth")) { //$NON-NLS-1$
if (origMsg.indexOf("cancel") >= 0) { //$NON-NLS-1$
msg = SshMessages.SSH_AUTH_CANCEL;
} else if (origMsg.indexOf("fail") >= 0) { //$NON-NLS-1$
msg = SshMessages.SSH_AUTH_FAIL;
}
}
if (!connectSucceeded) {
String hostPort = host;
if (port != 22) {
hostPort = hostPort + ':' + port;
}
msg = NLS.bind(SshMessages.ERROR_CONNECTING, hostPort, msg);
}
connectFailed(msg, msg);
} finally {
// make sure the terminal is disconnected when the thread ends
try {
@ -331,6 +357,7 @@ class SshConnection extends Thread {
private void connectFailed(String terminalText, String msg) {
Logger.log(terminalText);
fControl.displayTextInTerminal(terminalText);
fControl.setMsg(msg);
// fControl.setMsg(msg);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
* Copyright (c) 2000, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -9,9 +9,12 @@
* Michael Scharf (Wind River) - initial API and implementation
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified
* Johnson Ma (Wind River) - [218880] Add UI setting for ssh keepalives
* Martin Oberhuber (Wind River) - [206919] Improve SSH Terminal Error Reporting (Adopting code from org.eclipse.team.cvs.core)
*******************************************************************************/
package org.eclipse.tm.internal.terminal.ssh;
import java.lang.reflect.Field;
import org.eclipse.osgi.util.NLS;
public class SshMessages extends NLS {
@ -41,4 +44,54 @@ public class SshMessages extends NLS {
public static String KeyboardInteractiveDialog_message;
public static String KeyboardInteractiveDialog_labelConnection;
public static String ERROR_CONNECTING;
public static String TerminalCommunicationException_io;
public static String SSH_AUTH_CANCEL;
public static String SSH_AUTH_FAIL;
public static String com_jcraft_jsch_JSchException;
public static String java_io_IOException;
public static String java_io_EOFException;
public static String java_io_InterruptedIOException;
public static String java_net_UnknownHostException;
public static String java_net_ConnectException;
public static String java_net_SocketException;
public static String java_net_NoRouteToHostException;
// <Copied from org.eclipse.team.cvs.core / CVSCommunicationException (c) IBM 2000, 2007>
public static String getMessageFor(Throwable throwable) {
String message = getMessage(getMessageKey(throwable));
if (message == null) {
message = NLS.bind(SshMessages.TerminalCommunicationException_io, (new Object[] { throwable.toString() }));
} else {
message = NLS.bind(message, (new Object[] { throwable.getMessage() }));
}
return message;
}
private static String getMessageKey(Throwable t) {
String name = t.getClass().getName();
name = name.replace('.', '_');
return name;
}
// </Copied from org.eclipse.team.cvs.core / CVSCommunicationException>
// <Copied from org.eclipse.team.cvs.core / Policy (c) IBM 2000, 2005>
public static String getMessage(String key) {
try {
Field f = SshMessages.class.getDeclaredField(key);
Object o = f.get(null);
if (o instanceof String)
return (String) o;
} catch (SecurityException e) {
} catch (NoSuchFieldException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
}
return null;
}
// </Copied from org.eclipse.team.cvs.core / Policy>
}

View file

@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
# Copyright (c) 2000, 2008 Wind River Systems, Inc. and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@ -9,7 +9,11 @@
# Michael Scharf (Wind River) - initial API and implementation
# Martin Oberhuber (Wind River) - fixed copyright headers and beautified
# Johnson Ma (Wind River) - [218880] Add UI setting for ssh keepalives
# Martin Oberhuber (Wind River) - [206919] Improve SSH Terminal Error Reporting (Adopting code from org.eclipse.team.cvs.core)
###############################################################################
# NLS_MESSAGEFORMAT_VAR
HOST = Host
USER = User
PORT = Port
@ -32,3 +36,17 @@ UserValidationDialog_7=Saved passwords are stored on your computer in a file tha
KeyboardInteractiveDialog_message=Keyboard Interactive authentication for {0}
KeyboardInteractiveDialog_labelConnection=Enter values for the following connection: {0}
#These are from org.eclipse.team.cvs.core/messages.properties (c) IBM 2000, 2007
ERROR_CONNECTING=Error connecting {0} : {2}
TerminalCommunicationException_io=Communication error: {0}
SSH_AUTH_CANCEL=SSH Authentication cancelled.
SSH_AUTH_FAIL=SSH Authentication failed.
com_jcraft_jsch_JSchException=SSH client error: {0}
java_io_IOException=I/O exception occurred: {0}
java_io_EOFException=End of file encountered: {0}
java_io_InterruptedIOException=I/O has been interrupted.
java_net_UnknownHostException=Cannot locate host: {0}
java_net_ConnectException=Cannot connect to host: {0}
java_net_SocketException=Socket Exception: {0}
java_net_NoRouteToHostException={0}