mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-02 02:34:59 +00:00
feat: Add safe_read_json and safe_write_json functions to aider/utils.py
This commit is contained in:
parent
fb812acfe1
commit
7f1f2cb7ba
2 changed files with 20 additions and 0 deletions
|
@ -80,6 +80,8 @@ def make_repo(path=None):
|
|||
return repo
|
||||
|
||||
|
||||
import json
|
||||
|
||||
def is_image_file(file_name):
|
||||
"""
|
||||
Check if the given file name has an image file extension.
|
||||
|
@ -90,6 +92,21 @@ def is_image_file(file_name):
|
|||
file_name = str(file_name) # Convert file_name to string
|
||||
return any(file_name.endswith(ext) for ext in IMAGE_EXTENSIONS)
|
||||
|
||||
def safe_read_json(file_path):
|
||||
try:
|
||||
with open(file_path, 'r') as f:
|
||||
return json.load(f)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
def safe_write_json(file_path, data):
|
||||
try:
|
||||
with open(file_path, 'w') as f:
|
||||
json.dump(data, f)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def safe_abs_path(res):
|
||||
"Gives an abs path, which safely returns a full (not 8.3) windows path"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue