Skip to content

Commit

Permalink
Fix TypeError in error logging with f-strings
Browse files Browse the repository at this point in the history
This commit replaces logger.warning("Error is", e) with logger.warning(f"Error is {e}") to resolve a TypeError caused by inconsistent string formatting.
  • Loading branch information
abdullah-alnahas committed Apr 1, 2024
1 parent d3e314e commit 6fe1f1b
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions ansari_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def register(self, email, first_name, last_name, password_hash):
self.conn.commit()
return {"status": "success"}
except Exception as e:
logger.warning("Error is ", e)
logger.warning(f"Error is {e}")
return {"status": "failure", "error": str(e)}
finally:
if cur:
Expand All @@ -154,7 +154,7 @@ def account_exists(self, email):
result = cur.fetchone()
return result is not None
except Exception as e:
logger.warning("Error is ", e)
logger.warning(f"Error is {e}")
return False
finally:
if cur:
Expand All @@ -169,7 +169,7 @@ def save_token(self, user_id, token):
self.conn.commit()
return {"status": "success", "token": token}
except Exception as e:
logger.warning("Error is ", e)
logger.warning(f"Error is {e}")
return {"status": "failure", "error": str(e)}
finally:
if cur:
Expand All @@ -184,7 +184,7 @@ def save_reset_token(self, user_id, token):
self.conn.commit()
return {"status": "success", "token": token}
except Exception as e:
logger.warning("Error is ", e)
logger.warning(f"Error is {e}")
return {"status": "failure", "error": str(e)}
finally:
if cur:
Expand All @@ -202,7 +202,7 @@ def retrieve_user_info(self, email):
last_name = result[3]
return user_id, existing_hash, first_name, last_name
except Exception as e:
logger.warning("Error is ", e)
logger.warning(f"Error is {e}")
return None, None, None, None
finally:
if cur:
Expand All @@ -218,7 +218,7 @@ def add_feedback(self, user_id, thread_id, message_id, feedback_class, comment):
)
return {"status": "success"}
except Exception as e:
logger.warning("Error is ", e)
logger.warning(f"Error is {e}")
return {"status": "failure", "error": str(e)}
finally:
if cur:
Expand All @@ -234,7 +234,7 @@ def create_thread(self, user_id):
return {"status": "success", "thread_id": inserted_id}

except Exception as e:
logger.warning("Error is ", e)
logger.warning(f"Error is {e}")
return {"status": "failure", "error": str(e)}

finally:
Expand All @@ -254,7 +254,7 @@ def get_all_threads(self, user_id):
for x in result
]
except Exception as e:
logger.warning("Error is ", e)
logger.warning(f"Error is {e}")
return []
finally:
if cur:
Expand All @@ -277,7 +277,7 @@ def set_thread_name(self, thread_id, user_id, thread_name):
self.conn.commit()
return {"status": "success"}
except Exception as e:
logger.warning("Error is ", e)
logger.warning(f"Error is {e}")
return {"status": "failure", "error": str(e)}
finally:
if cur:
Expand All @@ -296,7 +296,7 @@ def append_message(self, user_id, thread_id, role, content, function_name=None):
self.conn.commit()
return {"status": "success"}
except Exception as e:
logger.warning("Error is ", e)
logger.warning(f"Error is {e}")
return {"status": "failure", "error": str(e)}
finally:
if cur:
Expand Down Expand Up @@ -360,7 +360,7 @@ def get_thread_llm(self, thread_id, user_id):
}
return retval
except Exception as e:
logger.warning("Error is ", e)
logger.warning(f"Error is {e}")
return {}
finally:
if cur:
Expand All @@ -384,7 +384,7 @@ def snapshot_thread(self, thread_id, user_id):
logger.info(f"Result is {result}")
return result
except Exception as e:
logger.warning("Error is ", e)
logger.warning(f"Error is {e}")
return {"status": "failure", "error": str(e)}
finally:
if cur:
Expand All @@ -399,7 +399,7 @@ def get_snapshot(self, share_uuid):
result = cur.fetchone()[0]
return result
except Exception as e:
logger.warning("Error is ", e)
logger.warning(f"Error is {e}")
return {}
finally:
if cur:
Expand All @@ -420,7 +420,7 @@ def delete_thread(self, thread_id, user_id):
self.conn.commit()
return {"status": "success"}
except Exception as e:
logger.warning("Error is ", e)
logger.warning(f"Error is {e}")
return {"status": "failure", "error": str(e)}
finally:
if cur:
Expand All @@ -434,7 +434,7 @@ def logout(self, user_id):
self.conn.commit()
return {"status": "success"}
except Exception as e:
logger.warning("Error is ", e)
logger.warning(f"Error is {e}")
return {"status": "failure", "error": str(e)}
finally:
if cur:
Expand Down Expand Up @@ -471,7 +471,7 @@ def update_password(self, user_id, new_password_hash):
cur.close()
return {"status": "success"}
except Exception as e:
logger.warning("Error is ", e)
logger.warning(f"Error is {e}")
return {"status": "failure", "error": str(e)}
finally:
if cur:
Expand Down

0 comments on commit 6fe1f1b

Please sign in to comment.