[anjuta] symbol-db: Provide better error message if one GDA backend is missing



commit bef03115c012da53e01822bba40ac520dcb815cb
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Sun Dec 7 19:44:15 2014 +0100

    symbol-db: Provide better error message if one GDA backend is missing

 plugins/symbol-db/benchmark/symbol-db/benchmark.c |    2 +-
 plugins/symbol-db/plugin.c                        |   16 ++++++++-----
 plugins/symbol-db/symbol-db-engine-core.c         |   25 ++++++++++++++------
 plugins/symbol-db/symbol-db-engine-core.h         |    9 ++++++-
 4 files changed, 35 insertions(+), 17 deletions(-)
---
diff --git a/plugins/symbol-db/benchmark/symbol-db/benchmark.c 
b/plugins/symbol-db/benchmark/symbol-db/benchmark.c
index 536dbea..1e44a00 100644
--- a/plugins/symbol-db/benchmark/symbol-db/benchmark.c
+++ b/plugins/symbol-db/benchmark/symbol-db/benchmark.c
@@ -108,7 +108,7 @@ int main (int argc, char** argv)
        
     engine = symbol_db_engine_new_full ("anjuta-tags", "benchmark-db");
   
-       if (symbol_db_engine_open_db (engine, root_dir, root_dir) == DB_OPEN_STATUS_FATAL)
+       if (symbol_db_engine_open_db (engine, root_dir, root_dir, NULL) == DB_OPEN_STATUS_FATAL)
        {
                g_message ("Could not open database: %s", root_dir);
                return -1;
diff --git a/plugins/symbol-db/plugin.c b/plugins/symbol-db/plugin.c
index 25732c0..52d22f7 100644
--- a/plugins/symbol-db/plugin.c
+++ b/plugins/symbol-db/plugin.c
@@ -1657,6 +1657,7 @@ on_project_root_added (AnjutaPlugin *plugin, const gchar *name,
        const gchar *root_uri;
        gchar *root_dir;
        GFile *gfile;
+       GError *error = NULL;
        
        sdb_plugin = ANJUTA_PLUGIN_SYMBOL_DB (plugin);
 
@@ -1672,9 +1673,10 @@ on_project_root_added (AnjutaPlugin *plugin, const gchar *name,
                anjuta_cache_path = anjuta_util_get_user_cache_file_path (".", NULL);
                if (symbol_db_engine_open_db (sdb_plugin->sdbe_globals, 
                                                          anjuta_cache_path, 
-                                                         PROJECT_GLOBALS) == DB_OPEN_STATUS_FATAL)
+                                                         PROJECT_GLOBALS,
+                                                         &error) == DB_OPEN_STATUS_FATAL)
                {
-                       g_error ("Opening global project under %s", anjuta_cache_path);
+                       g_error ("Opening global project under %s: %s", anjuta_cache_path, error->message);
                }
                g_free (anjuta_cache_path);
        
@@ -1725,7 +1727,7 @@ on_project_root_added (AnjutaPlugin *plugin, const gchar *name,
                /* we'll use the same values for db_directory and project_directory */
                DEBUG_PRINT ("Opening db %s and project_dir %s", root_dir, root_dir);
                gint open_status = symbol_db_engine_open_db (sdb_plugin->sdbe_project, root_dir, 
-                                                                                 root_dir);
+                                                                                 root_dir, &error);
 
                /* is it a fresh-new project? is it an imported project with 
                 * no 'new' symbol-db database but the 'old' one symbol-browser? 
@@ -1734,7 +1736,7 @@ on_project_root_added (AnjutaPlugin *plugin, const gchar *name,
                switch (open_status)
                {
                        case DB_OPEN_STATUS_FATAL:
-                               g_warning ("*** Error in opening db ***");
+                               g_warning ("*** Error in opening db: %s***", error->message);
                                return;
                                
                        case DB_OPEN_STATUS_NORMAL:
@@ -2012,6 +2014,7 @@ symbol_db_activate (AnjutaPlugin *plugin)
        gchar *anjuta_cache_path;
        gchar *ctags_path;
        GtkWidget *view, *label;
+       GError *error = NULL;
        
        DEBUG_PRINT ("SymbolDBPlugin: Activating SymbolDBPlugin plugin …");
        
@@ -2081,9 +2084,10 @@ symbol_db_activate (AnjutaPlugin *plugin)
        anjuta_cache_path = anjuta_util_get_user_cache_file_path (".", NULL);
        if (symbol_db_engine_open_db (sdb_plugin->sdbe_globals, 
                                                          anjuta_cache_path, 
-                                                         PROJECT_GLOBALS) == DB_OPEN_STATUS_FATAL)
+                                                         PROJECT_GLOBALS,
+                                                         &error) == DB_OPEN_STATUS_FATAL)
        {
-               g_error ("Opening global project under %s", anjuta_cache_path);
+               g_error ("Opening global project under %s: %s", anjuta_cache_path, error->message);
        }
        
        g_free (anjuta_cache_path);
diff --git a/plugins/symbol-db/symbol-db-engine-core.c b/plugins/symbol-db/symbol-db-engine-core.c
index f008820..8e33171 100644
--- a/plugins/symbol-db/symbol-db-engine-core.c
+++ b/plugins/symbol-db/symbol-db-engine-core.c
@@ -182,6 +182,12 @@ sdb_engine_add_new_symbol (SymbolDBEngine * dbe, const tagEntry * tag_entry,
 const GdaStatement *
 sdb_engine_get_statement_by_query_id (SymbolDBEngine * dbe, static_query_type query_id);
 
+GQuark
+symbol_db_engine_error_quark (void)
+{
+       return g_quark_from_static_string ("symbol-db-engine-error-quark");
+}
+
 /*
  * implementation starts here 
  */
@@ -2426,7 +2432,7 @@ sdb_engine_set_defaults_db_parameters (SymbolDBEngine * dbe)
  * because it is required and cannot be null.
  */
 static gboolean
-sdb_engine_connect_to_db (SymbolDBEngine * dbe, const gchar *cnc_string)
+sdb_engine_connect_to_db (SymbolDBEngine * dbe, const gchar *cnc_string, GError **error)
 {
        SymbolDBEnginePriv *priv;
 
@@ -2447,20 +2453,22 @@ sdb_engine_connect_to_db (SymbolDBEngine * dbe, const gchar *cnc_string)
         * be created 
         */
        priv->db_connection = gda_connection_open_from_string ("SQLite", cnc_string, NULL, 
-                                                                                  
GDA_CONNECTION_OPTIONS_THREAD_SAFE, NULL);   
+                                                                                  
GDA_CONNECTION_OPTIONS_THREAD_SAFE, error);
        
        if (!GDA_IS_CONNECTION (priv->db_connection))
        {
                g_warning ("Could not open connection to %s\n", cnc_string);
-               return FALSE;           
+               return FALSE;
        }
 
        priv->cnc_string = g_strdup (cnc_string);
        priv->sql_parser = gda_connection_create_parser (priv->db_connection);
        
-       if (!GDA_IS_SQL_PARSER (priv->sql_parser)) 
+       if (!GDA_IS_SQL_PARSER (priv->sql_parser))
        {
-               g_warning ("Could not create sql parser. Check your libgda installation");
+               g_set_error_literal (error, SYMBOL_DB_ENGINE_ERROR,
+                                    SYMBOL_DB_ENGINE_ERROR_INVALID_PARSER,
+                                    _("Could not create sql parser. Check your libgda installation"));
                return FALSE;
        }
        
@@ -2741,7 +2749,7 @@ sdb_engine_check_db_version_and_upgrade (SymbolDBEngine *dbe,
                }               
 
                /* 3. reconnect */
-               sdb_engine_connect_to_db (dbe, cnc_string);
+               sdb_engine_connect_to_db (dbe, cnc_string, NULL);
 
                /* 4. create fresh new tables, indexes, triggers etc.  */                       
                sdb_engine_create_db_tables (dbe, TABLES_SQL);
@@ -2767,6 +2775,7 @@ sdb_engine_check_db_version_and_upgrade (SymbolDBEngine *dbe,
  *        directory of /home/user/project/foo_prj/. On db it'll be represented as
  *        src/file.c. In this way you can move around the project dir without dealing
  *        with relative paths.
+ * @error: a place to store an error, or %NULL
  * 
  * Open, create or upgrade a database at given directory. 
  * Be sure to give a base_db_path with the ending '/' for directory.
@@ -2775,7 +2784,7 @@ sdb_engine_check_db_version_and_upgrade (SymbolDBEngine *dbe,
  */
 SymbolDBEngineOpenStatus
 symbol_db_engine_open_db (SymbolDBEngine * dbe, const gchar * base_db_path,
-                                                 const gchar * prj_directory)
+                                                 const gchar * prj_directory, GError **error)
 {
        SymbolDBEnginePriv *priv;
        gboolean needs_tables_creation = FALSE;
@@ -2812,7 +2821,7 @@ symbol_db_engine_open_db (SymbolDBEngine * dbe, const gchar * base_db_path,
                                                                priv->anjuta_db_file);
        DEBUG_PRINT ("Connecting to "
                                 "database with %s...", cnc_string);
-       connect_res = sdb_engine_connect_to_db (dbe, cnc_string);
+       connect_res = sdb_engine_connect_to_db (dbe, cnc_string, error);
        
 
        if (connect_res == FALSE)
diff --git a/plugins/symbol-db/symbol-db-engine-core.h b/plugins/symbol-db/symbol-db-engine-core.h
index cfe4f78..1dca828 100644
--- a/plugins/symbol-db/symbol-db-engine-core.h
+++ b/plugins/symbol-db/symbol-db-engine-core.h
@@ -41,11 +41,16 @@ G_BEGIN_DECLS
 #define SYMBOL_IS_DB_ENGINE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SYMBOL_TYPE_DB_ENGINE))
 #define SYMBOL_IS_DB_ENGINE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), SYMBOL_TYPE_DB_ENGINE))
 #define SYMBOL_DB_ENGINE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), SYMBOL_TYPE_DB_ENGINE, 
SymbolDBEngineClass))
+#define SYMBOL_DB_ENGINE_ERROR            (symbol_db_engine_error_quark ())
 
 typedef struct _SymbolDBEngineClass SymbolDBEngineClass;
 typedef struct _SymbolDBEngine SymbolDBEngine;
 typedef struct _SymbolDBEnginePriv SymbolDBEnginePriv;
 
+typedef enum {
+       SYMBOL_DB_ENGINE_ERROR_INVALID_PARSER,
+} SymbolDBEngineError;
+
 struct _SymbolDBEngineClass
 {
        GObjectClass parent_class;
@@ -77,7 +82,7 @@ typedef enum _SymbolDBEngineOpenStatus
        
 } SymbolDBEngineOpenStatus;
 
-
+GQuark symbol_db_engine_error_quark (void);
 GType sdb_engine_get_type (void) G_GNUC_CONST;
 
 
@@ -93,7 +98,7 @@ symbol_db_engine_set_ctags_path (SymbolDBEngine *dbe, const gchar * ctags_path);
 
 SymbolDBEngineOpenStatus
 symbol_db_engine_open_db (SymbolDBEngine *dbe, const gchar* base_db_path,
-                                                 const gchar * prj_directory);
+                                                 const gchar * prj_directory, GError **error);
 
 gboolean 
 symbol_db_engine_close_db (SymbolDBEngine *dbe);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]