From 980d9da7e933e5b2bc7e74d0d4945867fc5b14a3 Mon Sep 17 00:00:00 2001 From: Graham Mainwaring Date: Thu, 10 Jul 2014 22:28:56 -0400 Subject: [PATCH] Added exception handling to database creation and deletion. Fixes #8075. --- library/database/mysql_db | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/library/database/mysql_db b/library/database/mysql_db index 0d11abacf76..03934ed6826 100644 --- a/library/database/mysql_db +++ b/library/database/mysql_db @@ -319,7 +319,10 @@ def main(): changed = False if db_exists(cursor, db): if state == "absent": - changed = db_delete(cursor, db) + try: + changed = db_delete(cursor, db) + except Exception, e: + module.fail_json(msg="error deleting database: " + str(e)) elif state == "dump": rc, stdout, stderr = db_dump(module, login_host, login_user, login_password, db, target, @@ -340,7 +343,10 @@ def main(): module.exit_json(changed=True, db=db, msg=stdout) else: if state == "present": - changed = db_create(cursor, db, encoding, collation) + try: + changed = db_create(cursor, db, encoding, collation) + except Exception, e: + module.fail_json(msg="error creating database: " + str(e)) module.exit_json(changed=changed, db=db)