From cac5da1f04a608549b79f89902d776b4dee560c1 Mon Sep 17 00:00:00 2001 From: Chaos Pjeles Date: Fri, 3 Jan 2025 17:15:15 +0100 Subject: [PATCH] fixes #37 and #38 (#41) --- dogesec_commons/stixifier/serializers.py | 2 +- dogesec_commons/stixifier/summarizer.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/dogesec_commons/stixifier/serializers.py b/dogesec_commons/stixifier/serializers.py index 3a8343a..f799215 100644 --- a/dogesec_commons/stixifier/serializers.py +++ b/dogesec_commons/stixifier/serializers.py @@ -26,7 +26,7 @@ def validate_model(model): try: extractor = txt2stix.txt2stix.parse_model(model) except BaseException as e: - raise ValidationError(str(e)) + raise ValidationError(f"invalid model: {model}") return model def validate_extractor(typestr, types, name): diff --git a/dogesec_commons/stixifier/summarizer.py b/dogesec_commons/stixifier/summarizer.py index a4441ba..a1058c8 100644 --- a/dogesec_commons/stixifier/summarizer.py +++ b/dogesec_commons/stixifier/summarizer.py @@ -51,10 +51,12 @@ def parse_summarizer_model(value: str): splits = value.split(':', 1) provider = splits[0] if provider not in ALL_AI_EXTRACTORS: - raise Exception(f"invalid summary provider in `{value}`, must be one of [{list(ALL_AI_EXTRACTORS)}]") + raise ValidationError(f"invalid summary provider in `{value}`, must be one of [{list(ALL_AI_EXTRACTORS)}]") provider = get_provider(ALL_AI_EXTRACTORS[provider]) if len(splits) == 2: return provider(model=splits[1]) return provider() + except ValidationError: + raise except BaseException as e: - raise ValidationError(str(e)) from e \ No newline at end of file + raise ValidationError(f'invalid model: {value}') from e \ No newline at end of file