Closed spaude11 closed 7 months ago
Description: This is an example of exception handling where when user divide the number by zero, it throws exception.
Goal: The goal is to provide an example of exception handling, I will work on logging the exceptions within this week.
Code Snippet:
`import streamlit as st
try:
# Code block where an exception might occur
user_input = st.text_input("Enter a number:")
number = float(user_input)
result = 10 / number
st.write("Result:", result)
except ValueError:
# Handle specific exception(s) here
st.error("Please enter a valid number.")
except ZeroDivisionError:
st.error("Error: Division by zero!")
else:
# Optional block executed if no exception occurs in the try block
st.success("No error occurred!")
finally:
# Optional block always executed regardless of whether an exception occurred
st.write("This block always executes!")`
Environment Details: Pycharm Streamlit ChatGPT
Issue Resolution: This just a research comment since no issue resolution.
I am waiting for the push in the code for testing.
I Add something in here after testing
Description: The objective of this issue is to create a method for handling errors and exceptional conditions that will occur during the execution of program. The primary objective is to first test the website and check if there are any errors and logs the error into dropbox for later use. I integrated few try & catch blocks in main page, datasetmanagement page and feedback page
Steps to Reproduce: Few webpages are working, I tested the pages and check the code for Analyze input, Code review, Testing, logging methods. I inserted try and catch block in some and use already existing blocks and inserted exception logging
Expected Vs Actual Behavior: Expected Behaviour: Whenever the website fails to deliver the user request, the logging should register where the error happened and what was the error.
Actual Behaviour: The error log file is registering the errors but its not providing the time when that happened for the reference.
Code Snippets:
try:
if selected_app == "Home Page":
home_page()
elif selected_app == "Dataset Management":
dataset_management_page()
elif selected_app == "About Page":
about_page()
elif selected_app == "Feedback":
feedback_page()
except Exception as e:
error_log = f"An error occurred in {selected_app}: {str(e)}"
logging.error(error_log)
st.error(f"An error occurred: {str(e)}")
dropbox_logger.upload_error_log(error_log)
# Download the existing error log file from Dropbox
try:
_, existing_file = self.dbx.files_download('/Apps/Feedbackfiles/error_log.txt')
existing_error_log = existing_file.content.decode('utf-8')
except dropbox.exceptions.ApiError as e:
existing_error_log = ""
# Append the new error log to the existing content
updated_error_log = existing_error_log + "\n" + error_log
# Upload the updated error log back to Dropbox
with open('updated_error_log.txt', 'w') as f:
f.write(updated_error_log)
with open('updated_error_log.txt', 'rb') as f:
try:
self.dbx.files_upload(f.read(), '/Apps/Feedbackfiles/error_log.txt',
mode=dropbox.files.WriteMode.overwrite)
print("Error log updated and uploaded successfully to Dropbox.")
except dropbox.exceptions.ApiError as e:
print(f"Error updating error log on Dropbox: {e}")
Environment Details: Pycharm, Streamlit, Github, DropBox
For Issue Resolution: Use Try, Except, else and finally block as well as for storing the errors use Logging, Error Messages, Storage. Also insert the time stamp for error logging
Description: Adding time to the error logging for clear understanding when did the error happened.
Steps to Reproduce Whenever error happens in the code, it generate a history of error into a file. The file is then sent to dropbox for later review. I wanted to add time into the error log to show when does the error happens
Expected Vs Actual Behaviour The error log was not showing the time behaviour. I changed upload_error_log method in DropBoxLogger class. The error logging is working as expected now.
Code Snippets
def upload_error_log(self, error_log):
# Format the current time
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Download the existing error log file from Dropbox
try:
_, existing_file = self.dbx.files_download('/Apps/Feedbackfiles/error_log.txt')
existing_error_log = existing_file.content.decode('utf-8')
except dropbox.exceptions.ApiError:
existing_error_log = ""
# Append the new error log with timestamp to the existing content
updated_error_log = existing_error_log + f"\n{current_time} - {error_log}"
# Upload the updated error log back to Dropbox
with open('updated_error_log.txt', 'w') as f:
f.write(updated_error_log)
with open('updated_error_log.txt', 'rb') as f:
try:
self.dbx.files_upload(f.read(), '/Apps/Feedbackfiles/error_log.txt',
mode=dropbox.files.WriteMode.overwrite)
print("Error log updated and uploaded successfully to Dropbox.")
except dropbox.exceptions.ApiError as e:
print(f"Error updating error log on Dropbox: {e}")
Environment Details Pycharm, Streamlit, DropBox
Issue Resolution Added library date time and created method to add the date time into the errors
Great we can close the issue. However later on we'll need to add additional exception to detect more errors that can happen on the website. We can make an issue for this later on as its not too important just yet. This Looks great!
Description: The objective of this issue is to create a method for handling errors and exceptional conditions that will occur during the execution of program. The primary objective is to first test the website and check if there are any errors and logs the error into dropbox for later use.
Steps to Reproduce: Few webpages are working, I will test the website and check the code for Analyze input, Code review, Testing, logging methods.
Expected Vs Actual Behavior: Test the website and provide the expected and the actual behavior of the program
Code Snippets: Provide the error prone code from the file
Environment Details: Pycharm, Streamlit, Github
For Issue Resolution: Use Try, Except, else and finally block as well as for storing the errors use Logging, Error Messages, Storage