diff --git a/vsg/apply_rules.py b/vsg/apply_rules.py index 70af54e8..e5ab194a 100644 --- a/vsg/apply_rules.py +++ b/vsg/apply_rules.py @@ -6,6 +6,8 @@ from . import rule_list from . import utils from . import vhdlFile +from .exceptions import ClassifyError + def create_backup_file(sFileName): '''Copies existing file and adds .bak to the end.''' @@ -57,7 +59,17 @@ def apply_rules(commandLineArguments, oConfig, tIndexFileName): iIndex, sFileName = tIndexFileName dJsonEntry = {} lFileContent, eError = vhdlFile.utils.read_vhdlfile(sFileName) - oVhdlFile = vhdlFile.vhdlFile(lFileContent, sFileName, eError) + try: + oVhdlFile = vhdlFile.vhdlFile(lFileContent, sFileName, eError) + except ClassifyError as e: + fExitStatus = True + testCase = None + dJsonEntry["file_path"] = sFileName + dJsonEntry["violations"] = [] + sOutputStd = '' + sOutputErr = e.message + return fExitStatus, testCase, dJsonEntry, sOutputStd, sOutputErr + oVhdlFile.set_indent_map(dIndent) try: oRules = rule_list.rule_list( diff --git a/vsg/exceptions.py b/vsg/exceptions.py new file mode 100644 index 00000000..ca1ac5fd --- /dev/null +++ b/vsg/exceptions.py @@ -0,0 +1,11 @@ + +class ClassifyError(Exception): + ''' + Exception raised for errors when classifying VHDL Files. + ''' + + def __init__(self, message): + self.message = message + + def __str__(self): + return self.message diff --git a/vsg/vhdlFile/utils.py b/vsg/vhdlFile/utils.py index d0e2fa33..072694e4 100644 --- a/vsg/vhdlFile/utils.py +++ b/vsg/vhdlFile/utils.py @@ -1,4 +1,7 @@ +import sys + +from vsg import exceptions from vsg import parser @@ -399,10 +402,16 @@ def print_error_message(sToken, token, iToken, lObjects): iLine = calculate_line_number(iToken, lObjects) iColumn = calculate_column(iToken, lObjects) sModuleName = extract_module_name(token) - print(f'Error: Unexpected token detected while parsing {sModuleName} @ Line {iLine}, Column {iColumn} in file {lObjects[0].get_filename()}') - print(f' Expecting : {sToken}') - print(f' Found : {sFoundToken}') - exit() + + sErrorMesasge = '\n' + sErrorMessage += f'Error: Unexpected token detected while parsing {sModuleName} @ Line {iLine}, Column {iColumn} in file {lObjects[0].get_filename()}' + sErrorMesasge += '\n' + sErrorMessage += f' Expecting : {sToken}' + sErrorMesasge += '\n' + sErrorMessage += f' Found : {sFoundToken}' + sErrorMesasge += '\n' + + raise exceptions.ClassifyError(sErrorMessage) def extract_module_name(token):