From 9db2b46f70a07411127739e7f16b32d7d1d7f221 Mon Sep 17 00:00:00 2001 From: pyth0n1c Date: Tue, 18 Jun 2024 14:17:41 -0700 Subject: [PATCH 1/2] Add option to enable/disable verbose error printing to the terminal. This should make most operations easier to understand since the vast majority of errors are due to bad yml fields (or missing). --- contentctl/contentctl.py | 28 ++++++++++++++++++---------- contentctl/objects/config.py | 4 ++++ pyproject.toml | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/contentctl/contentctl.py b/contentctl/contentctl.py index e5c3718b..8f576e47 100644 --- a/contentctl/contentctl.py +++ b/contentctl/contentctl.py @@ -1,5 +1,10 @@ -from contentctl.actions.initialize import Initialize +import traceback +import sys +import warnings +import pathlib import tyro + +from contentctl.actions.initialize import Initialize from contentctl.objects.config import init, validate, build, new, deploy_acs, deploy_rest, test, test_servers, inspect, report, test_common, release_notes from contentctl.actions.validate import Validate from contentctl.actions.new_content import NewContent @@ -9,14 +14,10 @@ DirectorOutputDto, Build, ) - from contentctl.actions.test import Test from contentctl.actions.test import TestInputDto from contentctl.actions.reporting import ReportingInputDto, Reporting from contentctl.actions.inspect import Inspect -import sys -import warnings -import pathlib from contentctl.input.yml_reader import YmlReader from contentctl.actions.release_notes import ReleaseNotes @@ -183,7 +184,7 @@ def main(): - + config = None try: # Since some model(s) were constructed and not model_validated, we have to catch # warnings again when creating the cli @@ -220,9 +221,16 @@ def main(): else: raise Exception(f"Unknown command line type '{type(config).__name__}'") except Exception as e: - import traceback - traceback.print_exc() - traceback.print_stack() - #print(e) + if config is None: + print("There was a serious issue where the config file could not be created.\n" + "The entire stack trace is provided below (please include it if filing a bug report).\n") + traceback.print_exc() + elif config.verbose: + print("Verbose logging is enabled.\n" + "The entire stack trace has been provided below (please include it if filing a bug report):\n") + traceback.print_exc() + else: + print(e) + sys.exit(1) \ No newline at end of file diff --git a/contentctl/objects/config.py b/contentctl/objects/config.py index f036d132..96e652af 100644 --- a/contentctl/objects/config.py +++ b/contentctl/objects/config.py @@ -154,6 +154,10 @@ class Config_Base(BaseModel): path: DirectoryPath = Field(default=DirectoryPath("."), description="The root of your app.") app:CustomApp = Field(default_factory=CustomApp) + verbose:bool = Field(default=False, description="Enable verbose error logging, including a stacktrace. " + "This option makes debugging contentctl errors much easier, but produces way more " + "output than is useful under most uses cases. " + "Please use this flag if you are submitting a bug report or issue on GitHub.") @field_serializer('path',when_used='always') def serialize_path(path: DirectoryPath)->str: diff --git a/pyproject.toml b/pyproject.toml index ba7a0abd..9a15a612 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "contentctl" -version = "4.0.5" +version = "4.0.6" description = "Splunk Content Control Tool" authors = ["STRT "] license = "Apache 2.0" From a16e88a2c039c0f6a4bcedae8ff0391ebcd936b8 Mon Sep 17 00:00:00 2001 From: pyth0n1c Date: Tue, 18 Jun 2024 14:19:19 -0700 Subject: [PATCH 2/2] better description on error when verbose logging is not enabled. --- contentctl/contentctl.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contentctl/contentctl.py b/contentctl/contentctl.py index 8f576e47..f374ef8d 100644 --- a/contentctl/contentctl.py +++ b/contentctl/contentctl.py @@ -226,10 +226,12 @@ def main(): "The entire stack trace is provided below (please include it if filing a bug report).\n") traceback.print_exc() elif config.verbose: - print("Verbose logging is enabled.\n" + print("Verbose error logging is ENABLED.\n" "The entire stack trace has been provided below (please include it if filing a bug report):\n") traceback.print_exc() else: + print("Verbose error logging is DISABLED.\n" + "Please use the --verbose command line argument if you need more context for your error or file a bug report.") print(e) sys.exit(1)