Skip to content

Commit fa31a4a

Browse files
author
Taniya Mathur
committed
Fix MarkupError in publish.py exception handling
Replace {e} with self.console.print(str(e), style='red', markup=False) to prevent Rich markup parsing errors in exception messages
1 parent 2a8e211 commit fa31a4a

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

publish.py

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ def setup_artifacts_bucket(self):
377377
)
378378
sys.exit(1)
379379
else:
380-
self.console.print(f"[red]Error accessing bucket: {e}[/red]")
380+
self.console.print("[red]Error accessing bucket:[/red]")
381+
self.console.print(str(e), style="red", markup=False)
381382
sys.exit(1)
382383

383384
def get_file_checksum(self, file_path):
@@ -568,9 +569,10 @@ def build_and_package_template(self, directory, force_rebuild=False):
568569

569570
# Delete checksum on any failure to force rebuild next time
570571
self._delete_checksum_file(directory)
571-
self.log_verbose(f"Exception in build_and_package_template: {e}")
572+
self.log_verbose(f"Exception in build_and_package_template: {str(e)}")
572573
self.log_verbose(f"Traceback: {traceback.format_exc()}")
573-
self.console.print(f"[red]❌ Build failed for {directory}: {e}[/red]")
574+
self.console.print(f"[red]❌ Build failed for {directory}:[/red]")
575+
self.console.print(str(e), style="red", markup=False)
574576
sys.exit(1)
575577

576578
return True
@@ -816,9 +818,8 @@ def validate_lambda_builds(self):
816818
sys.exit(1)
817819

818820
except Exception as e:
819-
self.console.print(
820-
f"[red]❌ Error running lambda build validation: {e}[/red]"
821-
)
821+
self.console.print("[red]❌ Error running lambda build validation:[/red]")
822+
self.console.print(str(e), style="red", markup=False)
822823
if self.verbose:
823824
import traceback
824825

@@ -922,8 +923,9 @@ def _check_requirements_has_idp_common_pkg(self, func_dir):
922923
return False, "No idp_common_pkg found in requirements.txt"
923924
except Exception as e:
924925
self.console.print(
925-
f"[red]❌ Error reading requirements.txt in {func_dir}: {e}[/red]"
926+
f"[red]❌ Error reading requirements.txt in {func_dir}:[/red]"
926927
)
928+
self.console.print(str(e), style="red", markup=False)
927929
sys.exit(1)
928930

929931
def _extract_function_name(self, dir_name, template_path):
@@ -994,8 +996,9 @@ def construct_unknown(loader, node):
994996

995997
except Exception as e:
996998
self.console.print(
997-
f"[red]❌ Error extracting function name for {dir_name} from {template_path}: {e}[/red]"
999+
f"[red]❌ Error extracting function name for {dir_name} from {template_path}:[/red]"
9981000
)
1001+
self.console.print(str(e), style="red", markup=False)
9991002
sys.exit(1)
10001003

10011004
def _validate_idp_common_in_build(self, template_dir, function_name, source_path):
@@ -1041,10 +1044,10 @@ def _test_import_functionality(self, template_dir, function_name):
10411044
from idp_common import models
10421045
print("SUCCESS: All imports working")
10431046
except ImportError as e:
1044-
print(f"IMPORT_ERROR: {e}")
1047+
print(f"IMPORT_ERROR: {str(e)}")
10451048
sys.exit(1)
10461049
except Exception as e:
1047-
print(f"ERROR: {e}")
1050+
print(f"ERROR: {str(e)}")
10481051
sys.exit(1)
10491052
"""
10501053

@@ -1068,7 +1071,7 @@ def _test_import_functionality(self, template_dir, function_name):
10681071
except Exception as e:
10691072
if test_script.exists():
10701073
test_script.unlink()
1071-
return False, f"Test execution failed: {e}"
1074+
return False, f"Test execution failed: {str(e)}"
10721075

10731076
def upload_config_library(self):
10741077
"""Upload configuration library to S3"""
@@ -1093,7 +1096,8 @@ def upload_config_library(self):
10931096
try:
10941097
self.s3_client.upload_file(local_path, self.bucket, s3_key)
10951098
except ClientError as e:
1096-
self.console.print(f"[red]Error uploading {local_path}: {e}[/red]")
1099+
self.console.print(f"[red]Error uploading {local_path}:[/red]")
1100+
self.console.print(str(e), style="red", markup=False)
10971101
sys.exit(1)
10981102

10991103
self.console.print(
@@ -1166,7 +1170,8 @@ def package_ui(self):
11661170
)
11671171
sys.exit(1)
11681172
else:
1169-
self.console.print(f"[red]Error checking S3 for UI zipfile: {e}[/red]")
1173+
self.console.print("[red]Error checking S3 for UI zipfile:[/red]")
1174+
self.console.print(str(e), style="red", markup=False)
11701175
sys.exit(1)
11711176

11721177
return zipfile_name
@@ -1178,7 +1183,8 @@ def _upload_template_to_s3(self, template_path, s3_key, description):
11781183
self.s3_client.upload_file(template_path, self.bucket, s3_key)
11791184
self.console.print(f"[green]✅ {description} uploaded successfully[/green]")
11801185
except Exception as e:
1181-
self.console.print(f"[red]Failed to upload {description}: {e}[/red]")
1186+
self.console.print(f"[red]Failed to upload {description}:[/red]")
1187+
self.console.print(str(e), style="red", markup=False)
11821188
sys.exit(1)
11831189

11841190
def _check_and_upload_template(self, template_path, s3_key, description):
@@ -1199,8 +1205,9 @@ def _check_and_upload_template(self, template_path, s3_key, description):
11991205
self._upload_template_to_s3(template_path, s3_key, description)
12001206
else:
12011207
self.console.print(
1202-
f"[yellow]Could not check {description} existence: {e}[/yellow]"
1208+
f"[yellow]Could not check {description} existence:[/yellow]"
12031209
)
1210+
self.console.print(str(e), style="red", markup=False)
12041211

12051212
def build_main_template(self, webui_zipfile, components_needing_rebuild):
12061213
"""Build and package main template with smart detection"""
@@ -1376,7 +1383,8 @@ def build_main_template(self, webui_zipfile, components_needing_rebuild):
13761383
except Exception as e:
13771384
# Delete checksum on any failure to force rebuild next time
13781385
self._delete_checksum_file(".checksum")
1379-
self.console.print(f"[red]❌ Main template build failed: {e}[/red]")
1386+
self.console.print("[red]❌ Main template build failed:[/red]")
1387+
self.console.print(str(e), style="red", markup=False)
13801388
sys.exit(1)
13811389

13821390
def get_source_files_checksum(self, directory):
@@ -1630,8 +1638,9 @@ def _validate_python_syntax(self, directory):
16301638
py_compile.compile(file_path, doraise=True)
16311639
except py_compile.PyCompileError as e:
16321640
self.console.print(
1633-
f"[red]❌ Python syntax error in {file_path}: {e}[/red]"
1641+
f"[red]❌ Python syntax error in {file_path}[/red]"
16341642
)
1643+
self.console.print(str(e), style="red", markup=False)
16351644
return False
16361645
return True
16371646

@@ -1657,7 +1666,8 @@ def build_lib_package(self):
16571666

16581667
except Exception as e:
16591668
self._delete_checksum_file("lib/.checksum")
1660-
self.console.print(f"[red]❌ Failed to build lib package: {e}[/red]")
1669+
self.console.print("[red]❌ Failed to build lib package:[/red]")
1670+
self.console.print(str(e), style="red", markup=False)
16611671
sys.exit(1)
16621672

16631673
def _delete_checksum_file(self, checksum_path):
@@ -1789,7 +1799,7 @@ def set_public_acls(self):
17891799
self.console.print("[green]✅ Public ACLs set successfully[/green]")
17901800

17911801
except Exception as e:
1792-
raise Exception(f"Failed to set public ACLs: {e}")
1802+
raise Exception(f"Failed to set public ACLs: {str(e)}")
17931803

17941804
def run(self, args):
17951805
"""Main execution method"""
@@ -1905,7 +1915,8 @@ def run(self, args):
19051915
self.console.print("\n[yellow]Operation cancelled by user[/yellow]")
19061916
sys.exit(1)
19071917
except Exception as e:
1908-
self.console.print(f"[red]Error: {e}[/red]")
1918+
self.console.print("[red]Error:[/red]")
1919+
self.console.print(str(e), style="red", markup=False)
19091920
sys.exit(1)
19101921

19111922

0 commit comments

Comments
 (0)