SpecParsingError: only print context if available

Signed-off-by: Gregory Becker <becker33@llnl.gov>
This commit is contained in:
Gregory Becker 2025-04-22 17:28:10 -07:00
parent e66ae3959d
commit ce3fcf011f
No known key found for this signature in database
GPG Key ID: 2362541F6D14ED84

View File

@ -578,6 +578,7 @@ class SpecParsingError(spack.error.SpecSyntaxError):
def __init__(self, message, token, text):
message += f"\n{text}"
if token:
underline = f"\n{' '*token.start}{'^'*(token.end - token.start)}"
message += color.colorize(f"@*r{{{underline}}}")
super().__init__(message)