Skip to content

Commit 083663b

Browse files
committed
Add try-except for course creation
1 parent 9c8a6d1 commit 083663b

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ Project Link: [Math-Bot](https://github.com/AlinGeorgescu/Math-Bot)
146146
## Acknowledgements
147147
* [Othneil Drew](https://github.com/othneildrew/Best-README-Template) -
148148
README template
149+
* [Rod Pierce & Math is fun](http://www.mathsisfun.com) - Some graphics for the
150+
courses
149151

150152
<!-- MARKDOWN LINKS & IMAGES -->
151153
[contributors-shield]: https://img.shields.io/github/contributors/AlinGeorgescu/Math-Bot.svg?style=for-the-badge

courses.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
{
208208
"test_step_inner_id": 1,
209209
"test_step_text": "What do we use a geometric instrument for?",
210-
"test_step_ans": "We user a geometric instrument for drawing figures.",
210+
"test_step_ans": "We use a geometric instrument for drawing figures.",
211211
"course_id": 1
212212
},
213213
{

src/database_adapter/database_adapter.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,13 @@ def populate_postgres():
119119
sql.SQL(", ").join(map(sql.Literal, values)),
120120
)
121121

122-
cursor.execute(query)
122+
try:
123+
cursor.execute(query)
124+
except psycopg2.DatabaseError as err:
125+
cursor.close()
126+
CONN.rollback()
127+
LOGGER.critical(err.pgcode, err.pgerror)
128+
sys.exit()
123129

124130
# Check the existence of "course_steps" table (and create it).
125131
cursor.execute(
@@ -158,7 +164,13 @@ def populate_postgres():
158164
sql.SQL(", ").join(map(sql.Literal, values)),
159165
)
160166

161-
cursor.execute(query)
167+
try:
168+
cursor.execute(query)
169+
except psycopg2.DatabaseError as err:
170+
cursor.close()
171+
CONN.rollback()
172+
LOGGER.critical(err.pgcode, err.pgerror)
173+
sys.exit()
162174

163175
# Check the existence of "mid_questions" table (and create it).
164176
cursor.execute(
@@ -196,7 +208,13 @@ def populate_postgres():
196208
sql.SQL(", ").join(map(sql.Literal, values)),
197209
)
198210

199-
cursor.execute(query)
211+
try:
212+
cursor.execute(query)
213+
except psycopg2.DatabaseError as err:
214+
cursor.close()
215+
CONN.rollback()
216+
LOGGER.critical(err.pgcode, err.pgerror)
217+
sys.exit()
200218

201219
# Check the existence of "test_steps" table (and create it).
202220
cursor.execute(
@@ -235,7 +253,13 @@ def populate_postgres():
235253
sql.SQL(", ").join(map(sql.Literal, values)),
236254
)
237255

238-
cursor.execute(query)
256+
try:
257+
cursor.execute(query)
258+
except psycopg2.DatabaseError as err:
259+
cursor.close()
260+
CONN.rollback()
261+
LOGGER.critical(err.pgcode, err.pgerror)
262+
sys.exit()
239263

240264
# Check the existence of "users" table (and create it).
241265
cursor.execute(

0 commit comments

Comments
 (0)