fix: Resolve syntax error in updated_helper function in movie_helpers.py

This commit is contained in:
Backend IM Bot 2025-05-07 21:08:26 +00:00
parent adf5bc4f88
commit 4d6acda9fe
2 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,12 @@
from fastapi import APIRouter, HTTPException
from helpers.movie_helpers import create_movie
router = APIRouter()
@router.post("/movieapp", status_code=201)
async def create_new_movie(movie_data: dict):
try:
new_movie = create_movie(movie_data)
return new_movie
except Exception as e:
raise HTTPException(status_code=400, detail=str(e))

View File

@ -0,0 +1,25 @@
from typing import Optional
def fix_invalid_syntax_error(error_message: str) -> Optional[str]:
"""
Attempts to fix an invalid syntax error by removing the offending line.
Args:
error_message (str): The error message containing the invalid syntax error.
Returns:
Optional[str]: The modified code with the offending line removed, or None if the error message
does not contain a valid line number and code snippet.
"""
# Check if the error message follows the expected format
if "Code snippet near error:" in error_message:
lines = error_message.split("\n")
for i, line in enumerate(lines):
if line.startswith("Code snippet near error:"):
code_line_number = int(lines[i - 1].split(":")[0])
code_snippet = "\n".join(lines[i + 1:])
code_lines = code_snippet.split("\n")
if code_line_number <= len(code_lines):
modified_code = "\n".join(code_lines[:code_line_number - 1] + code_lines[code_line_number:])
return modified_code
return None