Add spack API warning with file/line (#48416)

This commit is contained in:
Harmen Stoppels 2025-01-06 11:43:04 +01:00 committed by GitHub
parent beadf06caa
commit 79027884c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -15,6 +15,10 @@
SHOW_BACKTRACE = False SHOW_BACKTRACE = False
class SpackAPIWarning(UserWarning):
"""Warning that formats with file and line number."""
class SpackError(Exception): class SpackError(Exception):
"""This is the superclass for all Spack errors. """This is the superclass for all Spack errors.
Subclasses can be found in the modules they have to do with. Subclasses can be found in the modules they have to do with.

View File

@ -503,9 +503,12 @@ def make_argument_parser(**kwargs):
return parser return parser
def send_warning_to_tty(message, *args): def send_warning_to_tty(message, category, filename, lineno, file=None, line=None):
"""Redirects messages to tty.warn.""" """Redirects messages to tty.warn."""
tty.warn(message) if category is spack.error.SpackAPIWarning:
tty.warn(f"{filename}:{lineno}: {message}")
else:
tty.warn(message)
def setup_main_options(args): def setup_main_options(args):