From 8f216dfcceafddd01cfa20885abecb04c0e41523 Mon Sep 17 00:00:00 2001 From: Derek Graeber Date: Mon, 1 Apr 2024 13:02:04 -0400 Subject: [PATCH] adding git error messaging --- CHANGELOG.md | 1 + seedfarmer/messages.py | 20 ++++++++++++++------ seedfarmer/mgmt/git_support.py | 23 +++++++++++++++++------ 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed0c459a..b3994500 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch - adding verbose messaging to session manager and hints to reconcile session issues - adding info for destroy and list deployments when no deployments found - refactored git support logic to separate python file +- added verbose messaging related to git issues ### Fixes - Add schema validation step checking that either `value` or `value_from` is present for each parameter diff --git a/seedfarmer/messages.py b/seedfarmer/messages.py index 6abb9b32..8fccb49f 100644 --- a/seedfarmer/messages.py +++ b/seedfarmer/messages.py @@ -1,15 +1,23 @@ from typing import Optional -checklist = """ Be sure to check: - 1. The session that you are executing the CLI from matches the ACCOUNT and REGION - where your toolchain is configured - 2. The session has permissions to access the proper toolchain role - """ - def no_deployment_found(deployment_name: Optional[str] = None) -> str: msg = "We found no deployments with your active session." if deployment_name: msg = f"We found no deployments named {deployment_name} with your active session." + checklist = """ Be sure to check: + 1. The session that you are executing the CLI from matches the ACCOUNT and REGION + where your toolchain is configured + 2. The session has permissions to access the proper toolchain role + """ + return msg + checklist + + +def git_error_support() -> str: + return """ + 1. Make sure your path to the repo is correct and valid (check your module manifests!) + 2. The credentials used to call SeedFarmer have access to the repo + 3. The credentials used to call SeedFarmer have not expired + """ diff --git a/seedfarmer/mgmt/git_support.py b/seedfarmer/mgmt/git_support.py index e200bd1c..e23755ac 100644 --- a/seedfarmer/mgmt/git_support.py +++ b/seedfarmer/mgmt/git_support.py @@ -6,7 +6,9 @@ import git from git import Repo +import seedfarmer.messages as messages from seedfarmer import config +from seedfarmer.errors import InvalidConfigurationError _logger: logging.Logger = logging.getLogger(__name__) @@ -70,16 +72,25 @@ def clone_module_repo(git_path: str) -> Tuple[str, str, Optional[str]]: if ref is not None: _logger.debug("Creating local repo and setting remote: %s into %s: ref=%s ", git_path, working_dir, ref) repo = Repo.init(working_dir) - git.Remote.create(repo, "origin", git_path, allow_unsafe_protocols) - repo.remotes["origin"].pull(ref, allow_unsafe_protocols=allow_unsafe_protocols) + try: + git.Remote.create(repo, "origin", git_path, allow_unsafe_protocols) + repo.remotes["origin"].pull(ref, allow_unsafe_protocols=allow_unsafe_protocols) + except git.GitError as ge: + raise InvalidConfigurationError(f"\n Cannot Clone Repo: {ge} {messages.git_error_support()}") else: _logger.debug("Cloning %s into %s: ref=%s depth=%s", git_path, working_dir, ref, depth) - repo = Repo.clone_from( - git_path, working_dir, branch=ref, depth=depth, allow_unsafe_protocols=allow_unsafe_protocols - ) + try: + repo = Repo.clone_from( + git_path, working_dir, branch=ref, depth=depth, allow_unsafe_protocols=allow_unsafe_protocols + ) + except git.GitError as ge: + raise InvalidConfigurationError(f"\n Cannot Clone Repo: {ge} {messages.git_error_support()}") else: _logger.debug("Pulling existing repo %s at %s: ref=%s", git_path, working_dir, ref) repo = Repo(working_dir) - repo.remotes["origin"].pull(ref, allow_unsafe_protocols=allow_unsafe_protocols) + try: + repo.remotes["origin"].pull(ref, allow_unsafe_protocols=allow_unsafe_protocols) + except git.GitError as ge: + raise InvalidConfigurationError(f"\n Cannot Clone Repo: {ge} {messages.git_error_support()}") commit_hash = get_commit_hash(repo) return (working_dir, module_directory, commit_hash)