Skip to content

Commit a59ec39

Browse files
Handle exceptions properly
1 parent 63b6cd1 commit a59ec39

File tree

4 files changed

+16
-19
lines changed

4 files changed

+16
-19
lines changed

scripts/release/build/image_build_process.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ def pull_image(self, image):
122122
try:
123123
docker_cmd.image.pull(image, quiet=True)
124124
except Exception as e:
125-
logger.error(f"Failed pulling image. {e}")
126-
raise e
125+
raise Exception("Failed pulling image.") from e
127126

128127
def get_manfiest_list_digest(self, image) -> Optional[str]:
129128
self.pull_image(image)
@@ -133,8 +132,7 @@ def get_manfiest_list_digest(self, image) -> Optional[str]:
133132
manifest = docker_cmd.image.inspect(image)
134133
return manifest.id
135134
except Exception as e:
136-
logger.error(f"Failed inspecting the image to get manifest list digest. {e}")
137-
raise e
135+
raise Exception("Failed inspecting the image to get manifest list digest") from e
138136

139137
def build_image(self, tags: list[str],
140138
dockerfile: str,

scripts/release/kubectl_mongodb/promote_kubectl_plugin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ def main():
6262

6363
if os.environ.get("SKIP_GITHUB_RELEASE_UPLOAD", "false").lower() == "false":
6464
github_artifacts = artifacts_tar + [checksum_file]
65-
upload_assets_to_github_release(github_artifacts, release_version)
65+
try:
66+
upload_assets_to_github_release(github_artifacts, release_version)
67+
except Exception as e:
68+
raise e
6669

6770

6871
# get_commit_from_tag gets the commit associated with a release tag, so that we can use that

scripts/release/kubectl_mongodb/utils.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,13 @@ def s3_path(filename: str, version: str) -> str:
4646
# the GitHub release as assets.
4747
def upload_assets_to_github_release(asset_paths: list[str], release_version: str):
4848
if not GITHUB_TOKEN:
49-
logger.info("ERROR: GITHUB_TOKEN environment variable not set.")
50-
sys.exit(1)
49+
raise Exception("ERROR: GITHUB_TOKEN environment variable not set.")
5150

5251
try:
5352
g = Github(GITHUB_TOKEN)
5453
repo = g.get_repo(GITHUB_REPO)
5554
except GithubException as e:
56-
logger.info(f"ERROR: Could not connect to GitHub or find repository '{GITHUB_REPO}', Error {e}.")
57-
sys.exit(1)
55+
raise Exception(f"ERROR: Could not connect to GitHub or find repository {GITHUB_REPO}") from e
5856

5957
try:
6058
gh_release = None
@@ -65,22 +63,18 @@ def upload_assets_to_github_release(asset_paths: list[str], release_version: str
6563
break
6664

6765
if gh_release is None:
68-
logger.error(
66+
raise Exception(
6967
f"Could not find release (published or draft) with tag '{release_version}'. Please ensure the release exists."
7068
)
71-
sys.exit(2)
7269
except GithubException as e:
73-
logger.debug(f"Failed to retrieve releases from the repository {GITHUB_REPO}. Error: {e}")
74-
sys.exit(2)
70+
raise Exception(f"Failed to retrieve releases from the repository {GITHUB_REPO}") from e
7571

7672
for asset_path in asset_paths:
7773
asset_name = os.path.basename(asset_path)
7874
logger.info(f"Uploading artifact '{asset_name}' to github release as asset")
7975
try:
8076
gh_release.upload_asset(path=asset_path, name=asset_name, content_type="application/gzip")
8177
except GithubException as e:
82-
logger.debug(f"ERROR: Failed to upload asset {asset_name}. Error: {e}")
83-
sys.exit(2)
78+
raise Exception(f"ERROR: Failed to upload asset {asset_name}") from e
8479
except Exception as e:
85-
logger.debug(f"An unexpected error occurred during upload of {asset_name}: {e}")
86-
sys.exit(2)
80+
raise Exception(f"An unexpected error occurred during upload of {asset_name}") from e

scripts/release/release_info.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,5 +198,7 @@ def manifest_list_digest_for_image(image: str) -> str:
198198
if release_info_filename is not None:
199199
with open(release_info_filename, "w") as file:
200200
file.write(release_info)
201-
202-
upload_assets_to_github_release([release_info_filename], args.version)
201+
try:
202+
upload_assets_to_github_release([release_info_filename], args.version)
203+
except Exception as e:
204+
raise e

0 commit comments

Comments
 (0)