Added proper exception handling for all try blocks that were missing except/finally clauses

Fixed the unclosed parenthesis in the format_message() call
Completed the message formatting section with proper parameters
Reorganized the code structure for better maintainability
Ensured proper error handling and cleanup throughout
This commit is contained in:
pacnpal
2024-11-15 14:14:57 +00:00
parent f8d383a55a
commit 807422e160

View File

@@ -134,7 +134,6 @@ class VideoProcessor:
except Exception as e:
return False, f"Download error: {str(e)}"
try:
# Get archive channel
guild = self.bot.get_guild(guild_id)
if not guild:
@@ -150,6 +149,11 @@ class VideoProcessor:
message = await message_manager.format_message(
author=author,
channel=channel,
url=item.url
)
except Exception as e:
return False, f"Failed to format message: {str(e)}"
# Upload to archive channel
try:
if not os.path.exists(file_path):
@@ -159,16 +163,16 @@ class VideoProcessor:
content=message,
file=discord.File(file_path)
)
return True, None
except discord.HTTPException as e:
return False, f"Failed to upload to Discord: {str(e)}"
except Exception as e:
return False, f"Failed to archive video: {str(e)}"
return True, None
except Exception as e:
return False, f"Processing error: {str(e)}"
logger.error(f"Error processing video: {traceback.format_exc()}")
return False, str(e)
finally:
# Clean up downloaded file
@@ -178,18 +182,6 @@ class VideoProcessor:
except Exception as e:
logger.error(f"Failed to clean up file {file_path}: {e}")
except Exception as e:
logger.error(f"Error processing video: {traceback.format_exc()}")
return False, str(e)
finally:
# Ensure file cleanup even on unexpected errors
if file_path and os.path.exists(file_path):
try:
os.unlink(file_path)
except Exception as e:
logger.error(f"Final cleanup failed for {file_path}: {e}")
async def cleanup(self):
"""Clean up resources"""
try: