From 8ec153841924d693acd5beb8d908b6ad3550bd57 Mon Sep 17 00:00:00 2001 From: Zack Winter <3457246+zackwintermdb@users.noreply.github.com> Date: Fri, 10 Apr 2026 12:56:08 -0700 Subject: [PATCH] SERVER-123867: Disable Printing out Env Variables in Typer Exception Handler (#51608) GitOrigin-RevId: 69bf0ec048d1048cdeefc3064570aba68d916aee --- bazel/resmoke/resmoke_config_generator.py | 5 ++++- .../bazel_rules_mongo/scripts/package_mongo_rules.py | 5 ++++- buildscripts/check_for_noexcept.py | 5 ++++- buildscripts/create_bazel_test_report.py | 5 ++++- buildscripts/evergreen_gen_streams_build_and_push_task.py | 5 ++++- buildscripts/fix_headers.py | 5 ++++- buildscripts/gather_failed_tests.py | 5 ++++- buildscripts/idl/gen_all_feature_flag_list.py | 2 +- buildscripts/mongo_toolchain.py | 2 +- buildscripts/monitor_build_status/cli.py | 5 ++++- buildscripts/s3_binary/upload.py | 5 ++++- buildscripts/s3_lock.py | 2 +- buildscripts/tests/test_activate_task.py | 2 ++ buildscripts/validate_commit_message.py | 5 ++++- buildscripts/validate_evg_project_config.py | 5 ++++- evergreen/activate_task.py | 5 ++++- .../security_reporting_scripts/upload_to_google_drive.py | 2 +- evergreen/functions/upload_sbom_via_silkbomb.py | 1 + modules_poc/merge_decls.py | 7 +++++-- modules_poc/private_headers.py | 5 ++++- modules_poc/upload.py | 5 ++++- tools/flag_sync/client.py | 2 +- tools/flag_sync/flag.py | 2 +- tools/flag_sync/namespace.py | 2 +- 24 files changed, 71 insertions(+), 23 deletions(-) diff --git a/bazel/resmoke/resmoke_config_generator.py b/bazel/resmoke/resmoke_config_generator.py index 5abcefad86b..6da8f687f53 100644 --- a/bazel/resmoke/resmoke_config_generator.py +++ b/bazel/resmoke/resmoke_config_generator.py @@ -28,5 +28,8 @@ def main( yaml.dump(content, fh) +app = typer.Typer(pretty_exceptions_show_locals=False) +app.command()(main) + if __name__ == "__main__": - typer.run(main) + app() diff --git a/buildscripts/bazel_rules_mongo/scripts/package_mongo_rules.py b/buildscripts/bazel_rules_mongo/scripts/package_mongo_rules.py index 1d72c1a4a20..c07f6aa0822 100644 --- a/buildscripts/bazel_rules_mongo/scripts/package_mongo_rules.py +++ b/buildscripts/bazel_rules_mongo/scripts/package_mongo_rules.py @@ -62,5 +62,8 @@ def get_current_version(): return data["tool"]["poetry"]["version"] +app = typer.Typer(pretty_exceptions_show_locals=False) +app.command()(main) + if __name__ == "__main__": - typer.run(main) + app() diff --git a/buildscripts/check_for_noexcept.py b/buildscripts/check_for_noexcept.py index 5a3e052e1f4..0cc52a54deb 100644 --- a/buildscripts/check_for_noexcept.py +++ b/buildscripts/check_for_noexcept.py @@ -589,5 +589,8 @@ def main( json.dump(check_result, f, indent=4) +app = typer.Typer(pretty_exceptions_show_locals=False) +app.command()(main) + if __name__ == "__main__": - typer.run(main) + app() diff --git a/buildscripts/create_bazel_test_report.py b/buildscripts/create_bazel_test_report.py index 7d31d324318..6eedf7581f0 100644 --- a/buildscripts/create_bazel_test_report.py +++ b/buildscripts/create_bazel_test_report.py @@ -76,5 +76,8 @@ def main(testlog_dir: str): print(f"No test.xml found within {testlog_dir}. Not creating a report.") +app = typer.Typer(pretty_exceptions_show_locals=False) +app.command()(main) + if __name__ == "__main__": - typer.run(main) + app() diff --git a/buildscripts/evergreen_gen_streams_build_and_push_task.py b/buildscripts/evergreen_gen_streams_build_and_push_task.py index a043aba581e..1c589e8ec32 100644 --- a/buildscripts/evergreen_gen_streams_build_and_push_task.py +++ b/buildscripts/evergreen_gen_streams_build_and_push_task.py @@ -92,5 +92,8 @@ def main( write_file(output_file, shrub_project.json()) +app = typer.Typer(pretty_exceptions_show_locals=False) +app.command()(main) + if __name__ == "__main__": - typer.run(main) + app() diff --git a/buildscripts/fix_headers.py b/buildscripts/fix_headers.py index 21fcd44b4dc..af7b9231438 100644 --- a/buildscripts/fix_headers.py +++ b/buildscripts/fix_headers.py @@ -273,5 +273,8 @@ def main( print(json_output) +app = typer.Typer(pretty_exceptions_show_locals=False) +app.command()(main) + if __name__ == "__main__": - typer.run(main) + app() diff --git a/buildscripts/gather_failed_tests.py b/buildscripts/gather_failed_tests.py index 46eb9dd022a..a80d04aa8c1 100644 --- a/buildscripts/gather_failed_tests.py +++ b/buildscripts/gather_failed_tests.py @@ -121,5 +121,8 @@ def main(build_events: str = "build_events.json"): _copy_bins_to_upload(upload_bin_dir, upload_lib_dir) +app = typer.Typer(pretty_exceptions_show_locals=False) +app.command()(main) + if __name__ == "__main__": - typer.run(main) + app() diff --git a/buildscripts/idl/gen_all_feature_flag_list.py b/buildscripts/idl/gen_all_feature_flag_list.py index 15952aa9f67..81b8a5ae1b4 100755 --- a/buildscripts/idl/gen_all_feature_flag_list.py +++ b/buildscripts/idl/gen_all_feature_flag_list.py @@ -94,7 +94,7 @@ def write_feature_flags_to_file(flags: list[str], filename: str): print(f"Generated: {os.path.realpath(output_file.name)}") -cli = typer.Typer() +cli = typer.Typer(pretty_exceptions_show_locals=False) @cli.command("turned-off-by-default") diff --git a/buildscripts/mongo_toolchain.py b/buildscripts/mongo_toolchain.py index 924a06b1169..bf12b70b39a 100644 --- a/buildscripts/mongo_toolchain.py +++ b/buildscripts/mongo_toolchain.py @@ -202,7 +202,7 @@ if __name__ == "__main__": import typer from typing_extensions import Annotated - _app = typer.Typer(add_completion=False) + _app = typer.Typer(add_completion=False, pretty_exceptions_show_locals=False) @_app.command() def main( diff --git a/buildscripts/monitor_build_status/cli.py b/buildscripts/monitor_build_status/cli.py index b4b51109514..edcbb43ff61 100644 --- a/buildscripts/monitor_build_status/cli.py +++ b/buildscripts/monitor_build_status/cli.py @@ -336,5 +336,8 @@ def main( orchestrator.evaluate_build_redness(notify) +app = typer.Typer(pretty_exceptions_show_locals=False) +app.command()(main) + if __name__ == "__main__": - typer.run(main) + app() diff --git a/buildscripts/s3_binary/upload.py b/buildscripts/s3_binary/upload.py index bc8d369d5dd..03c9ef56248 100644 --- a/buildscripts/s3_binary/upload.py +++ b/buildscripts/s3_binary/upload.py @@ -86,5 +86,8 @@ def main(local_source_directory: str, s3_destination_directory: str) -> None: ) +app = typer.Typer(pretty_exceptions_show_locals=False) +app.command()(main) + if __name__ == "__main__": - typer.run(main) + app() diff --git a/buildscripts/s3_lock.py b/buildscripts/s3_lock.py index 4ee5e610e03..a743a1bf64e 100644 --- a/buildscripts/s3_lock.py +++ b/buildscripts/s3_lock.py @@ -56,7 +56,7 @@ def acquire_s3_lock(bucket, key, content="locked"): raise -app = typer.Typer() +app = typer.Typer(pretty_exceptions_show_locals=False) @app.command() diff --git a/buildscripts/tests/test_activate_task.py b/buildscripts/tests/test_activate_task.py index e2750b4c433..989fb7634af 100644 --- a/buildscripts/tests/test_activate_task.py +++ b/buildscripts/tests/test_activate_task.py @@ -12,9 +12,11 @@ SCRIPT_PATH = Path(__file__).resolve().parents[2] / "evergreen" / "activate_task def load_under_test(): + fake_app = MagicMock() fake_typer = types.ModuleType("typer") fake_typer.Argument = lambda *args, **kwargs: None fake_typer.run = lambda *args, **kwargs: None + fake_typer.Typer = lambda *args, **kwargs: fake_app fake_typing_extensions = types.ModuleType("typing_extensions") fake_typing_extensions.Annotated = Annotated diff --git a/buildscripts/validate_commit_message.py b/buildscripts/validate_commit_message.py index edd1197e9e6..0be05ac4e09 100755 --- a/buildscripts/validate_commit_message.py +++ b/buildscripts/validate_commit_message.py @@ -268,5 +268,8 @@ def main( return +app = typer.Typer(pretty_exceptions_show_locals=False) +app.command()(main) + if __name__ == "__main__": - typer.run(main) + app() diff --git a/buildscripts/validate_evg_project_config.py b/buildscripts/validate_evg_project_config.py index 9599d08b96e..de56f53d03d 100644 --- a/buildscripts/validate_evg_project_config.py +++ b/buildscripts/validate_evg_project_config.py @@ -177,5 +177,8 @@ def main( sys.exit(exit_code) +app = typer.Typer(pretty_exceptions_show_locals=False) +app.command()(main) + if __name__ == "__main__": - typer.run(main) + app() diff --git a/evergreen/activate_task.py b/evergreen/activate_task.py index c0e0094922f..950a4101b72 100755 --- a/evergreen/activate_task.py +++ b/evergreen/activate_task.py @@ -60,5 +60,8 @@ def main( ) +app = typer.Typer(pretty_exceptions_show_locals=False) +app.command()(main) + if __name__ == "__main__": - typer.run(main) + app() diff --git a/evergreen/functions/security_reporting_scripts/upload_to_google_drive.py b/evergreen/functions/security_reporting_scripts/upload_to_google_drive.py index b0967284039..80e3918406c 100644 --- a/evergreen/functions/security_reporting_scripts/upload_to_google_drive.py +++ b/evergreen/functions/security_reporting_scripts/upload_to_google_drive.py @@ -8,7 +8,7 @@ from googleapiclient.discovery import build from googleapiclient.errors import HttpError from googleapiclient.http import MediaFileUpload -app = typer.Typer(add_completion=False) +app = typer.Typer(add_completion=False, pretty_exceptions_show_locals=False) @app.command() diff --git a/evergreen/functions/upload_sbom_via_silkbomb.py b/evergreen/functions/upload_sbom_via_silkbomb.py index 0b686359a58..9299b5fb475 100644 --- a/evergreen/functions/upload_sbom_via_silkbomb.py +++ b/evergreen/functions/upload_sbom_via_silkbomb.py @@ -10,6 +10,7 @@ from typing_extensions import Annotated app = typer.Typer( help="Checks for SBOM file changes in a PR and uploads it to Kondukto if changed.", add_completion=False, + pretty_exceptions_show_locals=False, ) diff --git a/modules_poc/merge_decls.py b/modules_poc/merge_decls.py index d68cbc4fa4a..eba5e6d40e8 100755 --- a/modules_poc/merge_decls.py +++ b/modules_poc/merge_decls.py @@ -95,7 +95,7 @@ def merge_decl(decl: Decl): or (decl["kind"] == "CLASS_DECL" and old["kind"] == "CLASS_TEMPLATE") or (decl["kind"] == "CLASS_TEMPLATE" and old["kind"] == "CLASS_DECL") ) - # assert decl["display_name"] == old["display_name"] # TODO ugh sometimes mongo:: screws it up + # assert decl["display_name"] == old["display_name"] # ugh sometimes mongo:: screws it up class Timer: @@ -295,5 +295,8 @@ def main( sys.exit(found_violations) # bools are ints, so False(0) is success and True(1) is failure +app = typer.Typer(pretty_exceptions_show_locals=False) +app.command()(main) + if __name__ == "__main__": - typer.run(main) + app() diff --git a/modules_poc/private_headers.py b/modules_poc/private_headers.py index 14391cfafd6..d43c9993221 100755 --- a/modules_poc/private_headers.py +++ b/modules_poc/private_headers.py @@ -298,5 +298,8 @@ def main( print("No _forTest violations found.") +app = typer.Typer(pretty_exceptions_show_locals=False) +app.command()(main) + if __name__ == "__main__": - typer.run(main) + app() diff --git a/modules_poc/upload.py b/modules_poc/upload.py index 0f2749e547c..30c7593e7ec 100755 --- a/modules_poc/upload.py +++ b/modules_poc/upload.py @@ -79,5 +79,8 @@ def main( print("uploaded unowned") +app = typer.Typer(pretty_exceptions_show_locals=False) +app.command()(main) + if __name__ == "__main__": - typer.run(main) + app() diff --git a/tools/flag_sync/client.py b/tools/flag_sync/client.py index 6f748e59936..9a224b70803 100644 --- a/tools/flag_sync/client.py +++ b/tools/flag_sync/client.py @@ -2,7 +2,7 @@ import typer from tools.flag_sync import flag, namespace -app = typer.Typer() +app = typer.Typer(pretty_exceptions_show_locals=False) app.add_typer(flag.app, name="flag") app.add_typer(namespace.app, name="namespace") diff --git a/tools/flag_sync/flag.py b/tools/flag_sync/flag.py index 280d777b3bf..c2854546aba 100644 --- a/tools/flag_sync/flag.py +++ b/tools/flag_sync/flag.py @@ -7,7 +7,7 @@ import typer from tools.flag_sync import util -app = typer.Typer() +app = typer.Typer(pretty_exceptions_show_locals=False) @app.command() diff --git a/tools/flag_sync/namespace.py b/tools/flag_sync/namespace.py index b1020ab49d8..e95aedbcee1 100644 --- a/tools/flag_sync/namespace.py +++ b/tools/flag_sync/namespace.py @@ -5,7 +5,7 @@ import typer from tools.flag_sync import util -app = typer.Typer() +app = typer.Typer(pretty_exceptions_show_locals=False) @app.command()