From 8315814bbddd0bf911c55a880d0ff0222794f706 Mon Sep 17 00:00:00 2001 From: serge-rider Date: Sat, 5 May 2018 23:17:53 +0300 Subject: [PATCH] #3256 PG debugger: check plugin installation and report to user. Error handling improvements. --- .../navigator/NavigatorHandlerObjectOpen.java | 5 +++-- .../dbeaver/debug/DBGBaseController.java | 8 +------- .../debug/core/model/DatabaseDebugTarget.java | 2 +- .../internal/impl/PostgreDebugController.java | 3 +++ .../internal/impl/PostgreDebugSession.java | 19 +++++++++++++++++++ 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/actions/navigator/NavigatorHandlerObjectOpen.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/actions/navigator/NavigatorHandlerObjectOpen.java index 564c1fd0b9..0b15f60fdf 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/actions/navigator/NavigatorHandlerObjectOpen.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/actions/navigator/NavigatorHandlerObjectOpen.java @@ -153,8 +153,9 @@ public class NavigatorHandlerObjectOpen extends NavigatorHandlerObjectBase imple IEditorPart editor = findEntityEditor(workbenchWindow, selectedNode); if (editor != null) { boolean settingsChanged = false; - if (editor.getEditorInput() instanceof IDatabaseEditorInput) { - settingsChanged = setInputAttributes((DatabaseEditorInput) editor.getEditorInput(), defaultPageId, defaultFolderId, attributes); + IEditorInput editorInput = editor.getEditorInput(); + if (editorInput instanceof IDatabaseEditorInput) { + settingsChanged = setInputAttributes((DatabaseEditorInput) editorInput, defaultPageId, defaultFolderId, attributes); } if (editor instanceof ITabbedFolderContainer && defaultFolderId != null) { // Activate default folder diff --git a/plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/DBGBaseController.java b/plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/DBGBaseController.java index d036601db8..e3bc120f17 100644 --- a/plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/DBGBaseController.java +++ b/plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/DBGBaseController.java @@ -67,13 +67,7 @@ public abstract class DBGBaseController implements DBGController { if (!dataSourceContainer.isConnected()) { throw new DBGException("Not connected to database"); } - try { - return createSession(monitor, configuration); - } catch (DBException e) { - String message = NLS.bind(DebugMessages.DatabaseDebugController_e_opening_debug_context, dataSourceContainer); - log.error(message, e); - throw new DBGException(message, e); - } + return createSession(monitor, configuration); } @Override diff --git a/plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/core/model/DatabaseDebugTarget.java b/plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/core/model/DatabaseDebugTarget.java index 52ee355a4b..4e00cfc95f 100644 --- a/plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/core/model/DatabaseDebugTarget.java +++ b/plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/core/model/DatabaseDebugTarget.java @@ -178,7 +178,7 @@ public class DatabaseDebugTarget extends DatabaseDebugElement implements IDataba } catch (DBGException e) { process.terminate(); throw new CoreException( - GeneralUtils.makeExceptionStatus(NLS.bind("Failed to connect {0} to the target", getName()), e)); + GeneralUtils.makeExceptionStatus(e)); } // Initiate breakpoints IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(modelIdentifier); diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugController.java b/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugController.java index 44c25b9522..9d5aa46f7a 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugController.java +++ b/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugController.java @@ -57,6 +57,9 @@ public class PostgreDebugController extends DBGBaseController { log.error(e1); } } + if (e instanceof DBGException) { + throw (DBGException)e; + } throw new DBGException("Error attaching debug session", e); } } diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugSession.java b/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugSession.java index aa847e7b44..8314711d62 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugSession.java +++ b/plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugSession.java @@ -92,6 +92,8 @@ public class PostgreDebugSession extends DBGJDBCSession { private static final String MAGIC_PORT = "PLDBGBREAK"; + private static final String SQL_CHECK_PLUGIN = "select 'Server version: ' || serverversionstr || '.\nProxy API version: ' || proxyapiver from pldbg_get_proxy_info()"; + private static final String SQL_ATTACH = "select pldbg_wait_for_target(?sessionid)"; private static final String SQL_ATTACH_TO_PORT = "select pldbg_attach_to_port(?portnumber)"; private static final String SQL_PREPARE_SLOT = " select pldbg_oid_debug(?objectid)"; @@ -361,6 +363,12 @@ public class PostgreDebugSession extends DBGJDBCSession { * procedure */ public void attach(DBRProgressMonitor monitor, Map configuration) throws DBException { + if (!checkDebugPlagin(monitor)) { + throw new DBGException("PostgreSQL debug plugin is not installed on the server.\n" + + "Refer to this WIKI article for installation instructions:\n" + + "https://github.com/dbeaver/dbeaver/wiki/PGDebugger#installation"); + } + int functionOid = CommonUtils.toInt(configuration.get(PostgreDebugConstants.ATTR_FUNCTION_OID)); String kind = String.valueOf(configuration.get(PostgreDebugConstants.ATTR_ATTACH_KIND)); boolean global = PostgreDebugConstants.ATTACH_KIND_GLOBAL.equals(kind); @@ -378,6 +386,17 @@ public class PostgreDebugSession extends DBGJDBCSession { } } + private boolean checkDebugPlagin(DBRProgressMonitor monitor) { + try (JDBCSession session = getControllerConnection().openSession(monitor, DBCExecutionPurpose.UTIL, "Check debug plugin installation")) { + String version = JDBCUtils.executeQuery(session, SQL_CHECK_PLUGIN); + log.debug("Debug plugin is installed:\n" + version); + return true; + } catch (Exception e) { + log.debug("Debug plugin not installed: " + e.getMessage()); + return false; + } + } + private void detachLocal(DBRProgressMonitor monitor) throws DBGException { try (JDBCSession session = getControllerConnection().openSession(monitor, DBCExecutionPurpose.UTIL, "Abort local session")) { JDBCUtils.executeQuery(session, composeAbortCommand()); -- GitLab