fix: improve error handling consistency
- Use TranslationProviderError instead of ValueError in azure_provider.py batch translation - Replace bare except blocks with specific ValidationError in config_test.py
This commit is contained in:
parent
daf1227caf
commit
38707ddabd
2 changed files with 9 additions and 3 deletions
|
|
@ -124,7 +124,10 @@ class AzureTranslationProvider(TranslationProvider):
|
|||
List of TranslationResult objects
|
||||
"""
|
||||
if not self.is_available():
|
||||
raise ValueError("Azure Translator API key not configured.")
|
||||
raise TranslationProviderError(
|
||||
provider=self.provider_name,
|
||||
message="Azure Translator API key not configured. Set AZURE_TRANSLATOR_KEY environment variable.",
|
||||
)
|
||||
|
||||
endpoint = f"{self._config.azure_translator_endpoint}/translate"
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ Unit tests for translation configuration
|
|||
"""
|
||||
|
||||
from typing import get_args
|
||||
|
||||
from pydantic import ValidationError
|
||||
|
||||
from cognee.tasks.translation.config import (
|
||||
get_translation_config,
|
||||
TranslationConfig,
|
||||
|
|
@ -63,7 +66,7 @@ def test_confidence_threshold_validation():
|
|||
assert 0.0 <= config_invalid_low.confidence_threshold <= 1.0, (
|
||||
f"Invalid low value should be clamped, got {config_invalid_low.confidence_threshold}"
|
||||
)
|
||||
except Exception:
|
||||
except ValidationError:
|
||||
pass # Expected validation error
|
||||
|
||||
try:
|
||||
|
|
@ -74,7 +77,7 @@ def test_confidence_threshold_validation():
|
|||
assert 0.0 <= config_invalid_high.confidence_threshold <= 1.0, (
|
||||
f"Invalid high value should be clamped, got {config_invalid_high.confidence_threshold}"
|
||||
)
|
||||
except Exception:
|
||||
except ValidationError:
|
||||
pass # Expected validation error
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue