Skip to content

Exceptions

Custom exceptions for translation providers.

This module defines exception classes used by the provider layer to handle error conditions in a consistent and type-safe manner.

Authors

Dimitrij Ray (dimitrij.ray@gdplabs.id)

References

NONE

LocaleNotFoundError(locale, message=None)

Bases: Exception

Raised when a requested locale is not available in the backend.

This exception is raised in strict mode when a locale is requested but cannot be found in the loaded translations.

Attributes:

Name Type Description
locale str

The locale identifier that was not found.

message str | None

Human-readable error message. Defaults to None.

Initialize LocaleNotFoundError.

Parameters:

Name Type Description Default
locale str

The locale identifier that was not found.

required
message str | None

Optional custom error message. Defaults to None, in which case a default message is generated.

None

__str__()

Return string representation of the error.

Returns:

Name Type Description
str str

Representation of the error.

ProviderConfigurationError(message)

Bases: Exception

Raised when provider configuration is invalid.

This exception is raised during provider initialization when the configuration parameters are invalid or inconsistent.

Common causes: 1. Both locales_dir and translations provided (mutually exclusive) 2. Neither locales_dir nor translations provided (one required) 3. Invalid file paths or malformed translation data

Attributes:

Name Type Description
message str

Human-readable error message explaining the issue.

Initialize ProviderConfigurationError.

Parameters:

Name Type Description Default
message str

Error message explaining the configuration issue.

required

__str__()

Return string representation of the error.

Returns:

Name Type Description
str str

Representation of the error.

TranslationKeyError(key, locale, message=None)

Bases: Exception

Raised when a translation key is not found in any locale.

This exception is raised in strict mode when a translation key is requested but cannot be found in the target locale or any fallback locales.

Attributes:

Name Type Description
key str

The translation key that was not found.

locale str

The locale where the key was requested.

message str | None

Human-readable error message. Defaults to None, in which case a default message is generated.

Initialize TranslationKeyError.

Parameters:

Name Type Description Default
key str

The translation key that was not found.

required
locale str

The locale where the key was requested.

required
message str | None

Optional custom error message. Defaults to None, in which case a default message is generated.

None

__str__()

Return string representation of the error.

Returns:

Name Type Description
str str

Representation of the error.