Skip to content

Commit

Permalink
Stop time bombing with RuntimeError's
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
  • Loading branch information
s0undt3ch committed Jan 23, 2024
1 parent 2c8f1b7 commit c6b1a08
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions salt/utils/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
Version parsing based on distutils.version which works under python 3
because on python 3 you can no longer compare strings against integers.
"""


import datetime
import inspect
import logging
import numbers
import os
import sys
import warnings

Expand Down Expand Up @@ -141,7 +140,7 @@ def warn_until(

if _version_ >= version:
caller = inspect.getframeinfo(sys._getframe(stacklevel - 1))
raise RuntimeError(
deprecated_message = (
"The warning triggered on filename '{filename}', line number "
"{lineno}, is supposed to be shown until version "
"{until_version} is released. Current version is now "
Expand All @@ -150,8 +149,15 @@ def warn_until(
lineno=caller.lineno,
until_version=version.formatted_version,
salt_version=_version_.formatted_version,
),
)
)
if os.environ.get("RAISE_DEPRECATIONS_RUNTIME_ERRORS", "0") == "1":
# We don't raise RuntimeError by default since that can breaks
# users systems. We do however want to raise them in a CI context.
raise RuntimeError(deprecated_message)
# Otherwise, print the deprecated message to STDERR
sys.stderr.write(f"\n{deprecated_message}\n")
sys.stderr.flush()

if _dont_call_warnings is False:
warnings.warn(
Expand Down Expand Up @@ -209,7 +215,7 @@ def warn_until_date(
today = _current_date or datetime.datetime.utcnow().date()
if today >= date:
caller = inspect.getframeinfo(sys._getframe(stacklevel - 1))
raise RuntimeError(
deprecated_message = (
"{message} This warning(now exception) triggered on "
"filename '{filename}', line number {lineno}, is "
"supposed to be shown until {date}. Today is {today}. "
Expand All @@ -221,6 +227,13 @@ def warn_until_date(
today=today.isoformat(),
),
)
if os.environ.get("RAISE_DEPRECATIONS_RUNTIME_ERRORS", "0") == "1":
# We don't raise RuntimeError by default since that can breaks
# users systems. We do however want to raise them in a CI context.
raise RuntimeError(deprecated_message)
# Otherwise, print the deprecated message to STDERR
sys.stderr.write(f"\n{deprecated_message}\n")
sys.stderr.flush()

if _dont_call_warnings is False:
warnings.warn(
Expand Down

0 comments on commit c6b1a08

Please sign in to comment.