chore: Improve error handling and logging in commit.py and git_api.py

This commit is contained in:
bobo 2024-05-19 18:52:04 +08:00
parent 2f3a423741
commit 4b6827d0f9
2 changed files with 8 additions and 4 deletions

View File

@ -73,13 +73,16 @@ def read_prompt_from_file(filename):
with open(filename, "r", encoding="utf-8") as file:
return file.read().strip()
except FileNotFoundError:
IDEService().log_info(
IDEService().ide_logging(
"error",
f"File {filename} not found. "
"Please make sure it exists in the same directory as the script."
"Please make sure it exists in the same directory as the script.",
)
sys.exit(1)
except Exception as e:
IDEService().log_info(f"An error occurred while reading the file {filename}: {e}")
IDEService().ide_logging(
"error", f"An error occurred while reading the file {filename}: {e}"
)
sys.exit(1)

View File

@ -7,6 +7,7 @@ import time
import requests
from lib.chatmark import TextEditor
from lib.ide_service import IDEService
def read_github_token():
@ -188,7 +189,7 @@ def get_github_repo(issue_repo=False):
repo = parts[-1].replace(".git", "")
username = parts[-2].split(":")[-1]
github_repo = f"{username}/{repo}"
print("current github repo:", github_repo, end="\n\n", file=sys.stderr, flush=True)
IDEService().ide_logging("debug", f"current github repo: {github_repo}")
return github_repo
except subprocess.CalledProcessError as e:
print(e)