From d8ae61dd227fd3a9c1e957d98c6ad5404c04eea9 Mon Sep 17 00:00:00 2001 From: Tomas Mlcoch Date: Tue, 2 Jul 2013 10:36:30 +0200 Subject: [PATCH] error: Add CRE_ASSERT return code. --- src/compression_wrapper.c | 10 +++++++++- src/error.h | 4 ++++ src/load_metadata.c | 4 +++- src/sqlite.c | 21 ++++++++++++++++++--- src/xml_file.c | 11 ++++++++++- 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/compression_wrapper.c b/src/compression_wrapper.c index 95cf12f..2c4b38e 100644 --- a/src/compression_wrapper.c +++ b/src/compression_wrapper.c @@ -285,12 +285,20 @@ cr_sopen(const char *filename, g_debug("%s: CR_CW_AUTO_DETECT_COMPRESSION cannot be used if " "mode is CR_CW_MODE_WRITE", __func__); assert(0); + g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_ASSERT, + "CR_CW_AUTO_DETECT_COMPRESSION cannot be used if " + "mode is CR_CW_MODE_WRITE"); + return NULL; } if (comtype == CR_CW_UNKNOWN_COMPRESSION) { g_debug("%s: CR_CW_UNKNOWN_COMPRESSION cannot be used if mode" - " is CR_CW_MODE_WRITE", __func__); + " is CR_CW_MODE_WRITE", __func__); assert(0); + g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_ASSERT, + "CR_CW_UNKNOWN_COMPRESSION cannot be used if mode " + "is CR_CW_MODE_WRITE"); + return NULL; } } diff --git a/src/error.h b/src/error.h index 5580568..439b343 100644 --- a/src/error.h +++ b/src/error.h @@ -74,6 +74,10 @@ typedef enum { (23) OpenSSL library related error */ CRE_CURL, /*!< (24) Curl library related error */ + CRE_ASSERT, /*!< + (25) Ideally this error should never happend. Nevertheless if + it happend, probable reason is that some values of createrepo_c + object was changed (by you - a programmer) in a bad way */ } cr_Error; /** Converts cr_Error return code to error string. diff --git a/src/load_metadata.c b/src/load_metadata.c index 11132f0..e86217d 100644 --- a/src/load_metadata.c +++ b/src/load_metadata.c @@ -307,7 +307,9 @@ cr_metadata_load_xml(cr_Metadata md, // and it SHOULD set only valid key values) g_critical("%s: Unknown hash table key selected", __func__); assert(0); - return CRE_ERROR; + g_set_error(err, CR_LOAD_METADATA_ERROR, CRE_ASSERT, + "Bad db type"); + return CRE_ASSERT; } if (g_hash_table_lookup(md->ht, new_key)) { diff --git a/src/sqlite.c b/src/sqlite.c index 812026d..b043740 100644 --- a/src/sqlite.c +++ b/src/sqlite.c @@ -1410,7 +1410,10 @@ cr_db_open(const char *path, cr_DatabaseType db_type, GError **err) db_create_other_tables(db, &tmp_err); break; default: + g_critical("%s: Bad db_type", __func__); assert(0); + g_set_error(err, CR_DB_ERROR, CRE_ASSERT, "Bad db type"); + return NULL; } if (tmp_err) { @@ -1432,7 +1435,10 @@ cr_db_open(const char *path, cr_DatabaseType db_type, GError **err) statements = cr_db_prepare_other_statements(db, &tmp_err); break; default: + g_critical("%s: Bad db_type", __func__); assert(0); + g_set_error(err, CR_DB_ERROR, CRE_ASSERT, "Bad db type"); + return NULL; } if (tmp_err) { @@ -1441,9 +1447,9 @@ cr_db_open(const char *path, cr_DatabaseType db_type, GError **err) return NULL; } - sqlitedb = g_new0(cr_SqliteDb, 1); - sqlitedb->db = db; - sqlitedb->type = db_type; + sqlitedb = g_new0(cr_SqliteDb, 1); + sqlitedb->db = db; + sqlitedb->type = db_type; switch (db_type) { case CR_DB_PRIMARY: @@ -1456,7 +1462,10 @@ cr_db_open(const char *path, cr_DatabaseType db_type, GError **err) sqlitedb->statements.oth = statements; break; default: + g_critical("%s: Bad db_type", __func__); assert(0); + g_set_error(err, CR_DB_ERROR, CRE_ASSERT, "Bad db type"); + return NULL; } return sqlitedb; @@ -1487,7 +1496,10 @@ cr_db_close(cr_SqliteDb *sqlitedb, GError **err) cr_db_destroy_other_statements(sqlitedb->statements.oth); break; default: + g_critical("%s: Bad db type", __func__); assert(0); + g_set_error(err, CR_DB_ERROR, CRE_ASSERT, "Bad db type"); + return CRE_ASSERT; } if (tmp_err) { @@ -1528,7 +1540,10 @@ cr_db_add_pkg(cr_SqliteDb *sqlitedb, cr_Package *pkg, GError **err) cr_db_add_other_pkg(sqlitedb->statements.oth, pkg, &tmp_err); break; default: + g_critical("%s: Bad db type", __func__); assert(0); + g_set_error(err, CR_DB_ERROR, CRE_ASSERT, "Bad db type"); + return CRE_ASSERT; } if (tmp_err) { diff --git a/src/xml_file.c b/src/xml_file.c index ff55b67..36934ea 100644 --- a/src/xml_file.c +++ b/src/xml_file.c @@ -114,7 +114,10 @@ cr_xmlfile_write_xml_header(cr_XmlFile *f, GError **err) xml_header = XML_OTHER_HEADER; break; default: + g_critical("%s: Bad file type", __func__); assert(0); + g_set_error(err, CR_XML_FILE_ERROR, CRE_ASSERT, "Bad file type"); + return CRE_ASSERT; } if (cr_printf(&tmp_err, f->f, xml_header, f->pkgs) == CR_CW_ERR) { @@ -149,7 +152,10 @@ cr_xmlfile_write_xml_footer(cr_XmlFile *f, GError **err) xml_footer = XML_OTHER_FOOTER; break; default: + g_critical("%s: Bad file type", __func__); assert(0); + g_set_error(err, CR_XML_FILE_ERROR, CRE_ASSERT, "Bad file type"); + return CRE_ASSERT; } cr_puts(f->f, xml_footer, &tmp_err); @@ -186,7 +192,10 @@ cr_xmlfile_add_pkg(cr_XmlFile *f, cr_Package *pkg, GError **err) xml = cr_xml_dump_other(pkg, &tmp_err); break; default: - assert(0); // This shoud not happend + g_critical("%s: Bad file type", __func__); + assert(0); + g_set_error(err, CR_XML_FILE_ERROR, CRE_ASSERT, "Bad file type"); + return CRE_ASSERT; } if (tmp_err) { -- 2.7.4