From 149e07a957d07ac6a09af9f827baed7bf69835b3 Mon Sep 17 00:00:00 2001
From: rluzuriaga <rodrigoluzuriaga@icloud.com>
Date: Mon, 6 Apr 2020 12:55:05 -0700
Subject: [PATCH] CLI load into existing table gracefully - PR Change 2

- Add message for other errors raised by the same exception that handles
the "table already exists" error.
- Add error message for any other unexpected exception thrown when
trying to create a table.
---
 pokedex/db/load.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/pokedex/db/load.py b/pokedex/db/load.py
index e994a25..eb0fe0a 100644
--- a/pokedex/db/load.py
+++ b/pokedex/db/load.py
@@ -207,8 +207,20 @@ def load(session, tables=[], directory=None, drop_tables=False, verbose=False, s
             if "already exists" in str(error.orig):
                 print("\n\nERROR:  The table '{}' already exists in the database. "
                     "Did you mean to use 'pokedex load -D'".format(table))
-                
+            sys.exit(1)
+
+            # If it happens to be some other error but raised by the same 
+            # exception, then an unexpected error message is sent with 
+            # the error included
+            else:
+                print("\n\n UNEXPECTED ERROR: ", error)
                 sys.exit(1)
+        
+        # In case any other exception not specified above is raised, an
+        # unexpected exception error is sent with the error included.
+        except Exception as error:
+            print("\n\nUNEXPECTED Error:  ", error)
+            sys.exit(1)
 
         print_status('%s/%s' % (n, len(table_objs)))
     print_done()