Limit verbose/debug levels#4836
Conversation
Enforced in code by the use of `Literal` type alias, runtime check follow the `normalize_*` pattern. Updated documentation and help texts to reflect the change. Related to #4814.
There was a problem hiding this comment.
Code Review
This pull request standardizes verbosity and debug levels by introducing dedicated type aliases and normalization functions for input validation. Feedback includes catching GeneralError in tmt/trying.py to prevent crashes, removing redundant None checks, and aligning the VerbosityLevel range with the help text. Additionally, restore the logging level in tmt/utils/init.py to avoid increased output noise.
| help=""" | ||
| Emit debugging information. Can be used up to four times | ||
| (``-d`` to ``-dddd``, or ``TMT_DEBUG=1`` to ``TMT_DEBUG=4``) | ||
| for increasingly detailed logging. | ||
| """, |
There was a problem hiding this comment.
Would be a good place to put the breakdown of what to expect in each verbosity level
There was a problem hiding this comment.
Depends what lands first, whether this PR or docs describing the levels. I tried to capture the current state of things, I can include the descriptions, but they are not ready yet.
There was a problem hiding this comment.
Ok, will revisit this comment once either of them get into a sprint
| #: Supported verbosity levels. | ||
| VERBOSITY_LEVELS = (0, 1, 2, 3, 4) | ||
| #: Supported debug levels. | ||
| DEBUG_LEVELS = (0, 1, 2, 3, 4) | ||
|
|
||
| #: A type of verbosity level values accepted by logging functions. | ||
| VerbosityLevel: 'TypeAlias' = Literal[0, 1, 2, 3, 4] | ||
| #: A type of debug level values accepted by logging functions. | ||
| DebugLevel: 'TypeAlias' = Literal[0, 1, 2, 3, 4] |
There was a problem hiding this comment.
See tmt.steps.ACTIONS about de-duplicating these
| DebugLevel: 'TypeAlias' = Literal[0, 1, 2, 3, 4] | ||
|
|
||
| DEFAULT_VERBOSITY_LEVEL: VerbosityLevel = 0 | ||
| DEFAULT_DEBUG_LEVEL: DebugLevel = 0 |
There was a problem hiding this comment.
Shouldn't debug level 0 be dropped (maybe in subsequent patch)?
There was a problem hiding this comment.
It's allowed, 0 means "no debugging messages". I think I could change the type and add another default to express what debug() accepts - Logger.debug_level can be set to 0, but debug(level=0) is indeed nonsense.
Enforced in code by the use of
Literaltype alias, runtime check follow thenormalize_*pattern. Updated documentation and help texts to reflect the change.Related to #4814.
Pull Request Checklist