77from click .core import ParameterSource
88
99from cwmscli .commands import commands_cwms
10+ from cwmscli .dss import dss_group
1011from cwmscli .load import __main__ as load
1112from cwmscli .usgs import usgs_group
1213from cwmscli .utils .click_help import add_version_to_help_tree
13- from cwmscli .utils .friendly_errors import to_user_facing_error
14+ from cwmscli .utils .friendly_errors import (
15+ cda_stack_trace ,
16+ format_cda_stack_trace ,
17+ to_user_facing_error ,
18+ )
19+ from cwmscli .utils .links import BUG_REPORT_URL
1420from cwmscli .utils .logging import (
1521 LoggingConfig ,
1622 apply_logging_policies ,
@@ -89,6 +95,7 @@ def cli(
8995cli .add_command (commands_cwms .clob_group )
9096cli .add_command (commands_cwms .users_group )
9197cli .add_command (load .load_group )
98+ cli .add_command (dss_group )
9299add_version_to_help_tree (cli )
93100
94101
@@ -111,9 +118,19 @@ def main() -> None:
111118 except SystemExit :
112119 raise
113120 except click .ClickException as e :
121+ debug = debug or logging .getLogger ().isEnabledFor (logging .DEBUG )
122+ if debug :
123+ server_stack_trace = cda_stack_trace (e )
124+ if server_stack_trace is not None :
125+ click .echo (format_cda_stack_trace (server_stack_trace ), err = True )
126+ raise SystemExit (e .exit_code )
114127 e .show ()
115128 raise SystemExit (e .exit_code )
116129 except Exception as e :
130+ # The environment switch supports failures before Click configures logging.
131+ # Once CLI setup has run, --log-level DEBUG enables the same behavior.
132+ debug = debug or logging .getLogger ().isEnabledFor (logging .DEBUG )
133+
117134 if is_cert_verify_error (e ) and not debug :
118135 # Keep this short, no stack trace.
119136 logging .error (
@@ -122,14 +139,21 @@ def main() -> None:
122139 click .echo (ssl_help_text (), err = True )
123140 raise SystemExit (2 )
124141
125- if not debug :
142+ if debug :
143+ server_stack_trace = cda_stack_trace (e )
144+ if server_stack_trace is not None :
145+ click .echo (format_cda_stack_trace (server_stack_trace ), err = True )
146+ raise SystemExit (1 )
147+ else :
126148 friendly_error = to_user_facing_error (e )
127149 if friendly_error is not None :
128150 logging .debug ("Suppressed traceback for CLI exception" , exc_info = e )
129151 friendly_error .show ()
130152 raise SystemExit (friendly_error .exit_code )
131153
132- # If debug is enabled (or it's not a cert verify error), keep the normal failure behavior.
154+ click .echo (f"Unexpected error. Report it at { BUG_REPORT_URL } " , err = True )
155+ # Preserve raw exception behavior when CDA did not provide a server stack
156+ # trace so an issue report includes useful diagnostic details.
133157 raise
134158
135159
0 commit comments