mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 10:14:59 +00:00
refactor: Simplify config file check and error handling
This commit is contained in:
parent
c6d1c45abc
commit
989e7c18fb
1 changed files with 6 additions and 29 deletions
|
@ -27,6 +27,7 @@ from .dump import dump # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
def check_config_files_for_yes(config_files):
|
def check_config_files_for_yes(config_files):
|
||||||
|
found = False
|
||||||
for config_file in config_files:
|
for config_file in config_files:
|
||||||
if Path(config_file).exists():
|
if Path(config_file).exists():
|
||||||
try:
|
try:
|
||||||
|
@ -36,17 +37,10 @@ def check_config_files_for_yes(config_files):
|
||||||
print("Configuration error detected.")
|
print("Configuration error detected.")
|
||||||
print(f"The file {config_file} contains a line starting with 'yes:'")
|
print(f"The file {config_file} contains a line starting with 'yes:'")
|
||||||
print("Please replace 'yes:' with 'yes-always:' in this file.")
|
print("Please replace 'yes:' with 'yes-always:' in this file.")
|
||||||
print("Configuration files are searched for in this order:")
|
found = True
|
||||||
for cf in config_files:
|
|
||||||
print(f" - {cf}")
|
|
||||||
print(
|
|
||||||
"For more information, refer to the aider documentation on"
|
|
||||||
" configuration."
|
|
||||||
)
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error reading config file {config_file}: {e}")
|
pass
|
||||||
return False
|
return found
|
||||||
|
|
||||||
|
|
||||||
def get_git_root():
|
def get_git_root():
|
||||||
|
@ -390,7 +384,7 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
||||||
if "'bool' object has no attribute 'strip'" in str(e):
|
if "'bool' object has no attribute 'strip'" in str(e):
|
||||||
if check_config_files_for_yes(default_config_files):
|
if check_config_files_for_yes(default_config_files):
|
||||||
return 1
|
return 1
|
||||||
raise
|
raise e
|
||||||
|
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print("Config files search order, if no --config:")
|
print("Config files search order, if no --config:")
|
||||||
|
@ -408,24 +402,7 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
||||||
loaded_dotenvs = load_dotenv_files(git_root, args.env_file, args.encoding)
|
loaded_dotenvs = load_dotenv_files(git_root, args.env_file, args.encoding)
|
||||||
|
|
||||||
# Parse again to include any arguments that might have been defined in .env
|
# Parse again to include any arguments that might have been defined in .env
|
||||||
try:
|
args = parser.parse_args(argv)
|
||||||
args = parser.parse_args(argv)
|
|
||||||
except AttributeError as e:
|
|
||||||
if "'bool' object has no attribute 'strip'" in str(e):
|
|
||||||
io.tool_error("Configuration error detected.")
|
|
||||||
io.tool_output("It seems you have 'yes:' in one of your configuration files.")
|
|
||||||
io.tool_output(
|
|
||||||
"Please replace 'yes:' with 'yes-always:' in the relevant .aider.conf.yml file."
|
|
||||||
)
|
|
||||||
io.tool_output("Configuration files are searched for in this order:")
|
|
||||||
for config_file in default_config_files:
|
|
||||||
io.tool_output(f" - {config_file}")
|
|
||||||
io.tool_output(
|
|
||||||
"For more information, refer to the aider documentation on configuration."
|
|
||||||
)
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
|
|
||||||
if not args.verify_ssl:
|
if not args.verify_ssl:
|
||||||
import httpx
|
import httpx
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue