You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add smarter error handling in checker bundles
* Add more informative errors for input file errors
* Add more test cases for error handling
Fixes#24
Signed-off-by: Pierre R. Mai <pmai@pmsf.de>
Signed-off-by: Timm Ruppert <timm.ruppert@persival.de>
Co-authored-by: Timm Ruppert <timm.ruppert@persival.de>
description=f"Version field value {message.version.version_major}.{message.version.version_minor}.{message.version.version_patch} is not the expected version {'.'.join([str(s) forsinexpected_version])}.",
106
-
level=IssueSeverity.ERROR,
107
-
rule_uid=exp_version_rule_uid,
108
-
)
109
-
110
-
logging.info(
111
-
f"Issues found - {result.get_checker_issue_count(checker_bundle_name=constants.BUNDLE_NAME, checker_id=deserialization_constants.CHECKER_ID)}"
112
-
)
113
-
114
-
# TODO: Add logic to deal with error or to skip it
description=f"Deserialized message is not of expected type {expected_type}.",
87
+
level=IssueSeverity.ERROR,
88
+
rule_uid=type_rule_uid,
89
+
)
90
+
ifnotmessage.HasField("version"):
91
+
issue_id=result.register_issue(
92
+
checker_bundle_name=constants.BUNDLE_NAME,
93
+
checker_id=deserialization_constants.CHECKER_ID,
94
+
description="Version field is not set in top-level message.",
95
+
level=IssueSeverity.ERROR,
96
+
rule_uid=version_rule_uid,
97
+
)
98
+
elif (
99
+
expected_versionisnotNone
100
+
and (
101
+
int(message.version.version_major),
102
+
int(message.version.version_minor),
103
+
int(message.version.version_patch),
104
+
)
105
+
!=expected_version
106
+
):
107
+
issue_id=result.register_issue(
108
+
checker_bundle_name=constants.BUNDLE_NAME,
109
+
checker_id=deserialization_constants.CHECKER_ID,
110
+
description=f"Version field value {message.version.version_major}.{message.version.version_minor}.{message.version.version_patch} is not the expected version {'.'.join([str(s) forsinexpected_version])}.",
111
+
level=IssueSeverity.ERROR,
112
+
rule_uid=exp_version_rule_uid,
113
+
)
114
+
115
+
logging.info(
116
+
f"Issues found - {result.get_checker_issue_count(checker_bundle_name=constants.BUNDLE_NAME, checker_id=deserialization_constants.CHECKER_ID)}"
117
+
)
118
+
119
+
result.set_checker_status(
120
+
checker_bundle_name=constants.BUNDLE_NAME,
121
+
checker_id=deserialization_constants.CHECKER_ID,
122
+
status=StatusType.COMPLETED,
123
+
)
124
+
125
+
exceptExceptionase:
126
+
logging.error(f"Error during deserialization checks: {e}")
description="Evaluates messages in the trace file against the OSI Rules of the given OSI version to guarantee they are in conformance with the standard OSI rules.",
454
-
summary="Checker validating OSI Rules compliance of messages in a trace file",
455
-
)
456
-
457
448
ifexpected_versionisNone:
458
449
logging.info(
459
450
f"No expected version, falling back to {'.'.join([str(s) forsinfallback_version])} rules"
f"Read {'custom'ifcustom_rules_fileelse'standard'} rules file for version {'.'.join([str(s) forsinrules_version])}"
477
-
)
478
462
479
-
exceptFileNotFoundError:
480
-
logging.info(
481
-
f"No {'custom'ifcustom_rules_fileelse'standard'} rules file for expected version {'.'.join([str(s) forsinexpected_version])}, falling back to standard {'.'.join([str(s) forsinfallback_version])} rules"
482
-
)
483
-
fallback_rules_file= (
484
-
impresources.files(rulesyml)
485
-
/f"osi_{'_'.join(map(str,fallback_version))}.yml"
486
-
)
487
-
withfallback_rules_file.open("rt") asfile:
488
-
rules=yaml.safe_load(file)
489
-
rules_version=fallback_version
490
-
logging.info(
491
-
f"Read standard rules file for version {'.'.join([str(s) forsinrules_version])}"
492
-
)
493
-
494
-
version_rule_uid=result.register_rule(
495
-
checker_bundle_name=constants.BUNDLE_NAME,
496
-
checker_id=osirules_constants.CHECKER_ID,
497
-
emanating_entity="asam.net",
498
-
standard="osi",
499
-
definition_setting="3.0.0",
500
-
rule_full_name="osirules.version_is_set",
501
-
)
502
-
503
-
exp_version_rule_uid=result.register_rule(
463
+
result.register_checker(
504
464
checker_bundle_name=constants.BUNDLE_NAME,
505
465
checker_id=osirules_constants.CHECKER_ID,
506
-
emanating_entity="asam.net",
507
-
standard="osi",
508
-
definition_setting="3.0.0",
509
-
rule_full_name="osirules.expected_version",
466
+
description="Evaluates messages in the trace file against the OSI Rules of the given OSI version to guarantee they are in conformance with the standard OSI rules.",
467
+
summary="Checker validating OSI Rules compliance of messages in a trace file",
description=f"Version field value {message.version.version_major}.{message.version.version_minor}.{message.version.version_patch} is not the expected version {'.'.join([str(s) forsinexpected_version])}.",
524
+
ifnotmessage.HasField("version"):
525
+
register_issue(
526
+
result,
527
+
message,
528
+
index,
529
+
time,
530
+
version_rule_uid,
531
+
IssueSeverity.ERROR,
532
+
description="Version field is not set in top-level message.",
533
+
)
534
+
elif (
535
+
expected_versionisnotNone
536
+
and (
537
+
int(message.version.version_major),
538
+
int(message.version.version_minor),
539
+
int(message.version.version_patch),
540
+
)
541
+
!=expected_version
542
+
):
543
+
register_issue(
544
+
result,
545
+
message,
546
+
index,
547
+
time,
548
+
exp_version_rule_uid,
549
+
IssueSeverity.ERROR,
550
+
description=f"Version field value {message.version.version_major}.{message.version.version_minor}.{message.version.version_patch} is not the expected version {'.'.join([str(s) forsinexpected_version])}.",
551
+
)
552
+
553
+
id_message_map= {}
554
+
record_message_ids(message, id_message_map)
555
+
check_message_against_rules(
556
+
message, rule_uid_map, id_message_map, index, time, result
552
557
)
553
558
554
-
id_message_map= {}
555
-
record_message_ids(message, id_message_map)
556
-
check_message_against_rules(
557
-
message, rule_uid_map, id_message_map, index, time, result
559
+
logging.info(
560
+
f"Issues found - {result.get_checker_issue_count(checker_bundle_name=constants.BUNDLE_NAME, checker_id=osirules_constants.CHECKER_ID)}"
558
561
)
559
562
560
-
logging.info(
561
-
f"Issues found - {result.get_checker_issue_count(checker_bundle_name=constants.BUNDLE_NAME, checker_id=osirules_constants.CHECKER_ID)}"
562
-
)
563
+
result.set_checker_status(
564
+
checker_bundle_name=constants.BUNDLE_NAME,
565
+
checker_id=osirules_constants.CHECKER_ID,
566
+
status=StatusType.COMPLETED,
567
+
)
563
568
564
-
# TODO: Add logic to deal with error or to skip it
565
-
result.set_checker_status(
566
-
checker_bundle_name=constants.BUNDLE_NAME,
567
-
checker_id=osirules_constants.CHECKER_ID,
568
-
status=StatusType.COMPLETED,
569
-
)
569
+
exceptExceptionase:
570
+
logging.error(f"Error during osirules checks: {e}")
0 commit comments