fix: Resolve syntax error in updated_helper function in movie_helpers.py
This commit is contained in:
parent
adf5bc4f88
commit
4d6acda9fe
@ -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))
|
25
helpers/generic_helpers.py
Normal file
25
helpers/generic_helpers.py
Normal 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
|
Loading…
x
Reference in New Issue
Block a user