跳到内容

错误

本节包含 distilabel 自定义错误。与 异常 不同,distilabel 中的错误用于处理无法预测且无法以受控方式处理的意外情况。

DistilabelError

所有 Distilabel 特定错误共享的通用功能的 mixin 类。

属性

名称 类型 描述
message

描述错误的消息。

page

来自 PydanticErrorCodes 枚举的可选错误代码。

示例

raise DistilabelUserError("This is an error message.")
This is an error message.

raise DistilabelUserError("This is an error message.", page="sections/getting_started/faq/")
This is an error message.
For further information visit 'https://distilabel.argilla.com.cn/latest/sections/getting_started/faq/'
src/distilabel/errors.py 中的源代码
class DistilabelError:
    """A mixin class for common functionality shared by all Distilabel-specific errors.

    Attributes:
        message: A message describing the error.
        page: An optional error code from PydanticErrorCodes enum.

    Examples:
        ```python
        raise DistilabelUserError("This is an error message.")
        This is an error message.

        raise DistilabelUserError("This is an error message.", page="sections/getting_started/faq/")
        This is an error message.
        For further information visit 'https://distilabel.argilla.com.cn/latest/sections/getting_started/faq/'
        ```
    """

    def __init__(self, message: str, *, page: Optional[str] = None) -> None:
        self.message = message
        self.page = page

    def __str__(self) -> str:
        if self.page is None:
            return self.message
        else:
            return f"{self.message}\n\nFor further information visit '{DISTILABEL_DOCS_URL}{self.page}'"

DistilabelUserError

基类: DistilabelError, ValueError

我们可以重定向到文档中给定页面的 ValueError。

src/distilabel/errors.py 中的源代码
class DistilabelUserError(DistilabelError, ValueError):
    """ValueError that we can redirect to a given page in the documentation."""

    pass

DistilabelTypeError

基类: DistilabelError, TypeError

我们可以重定向到文档中给定页面的 TypeError。

src/distilabel/errors.py 中的源代码
class DistilabelTypeError(DistilabelError, TypeError):
    """TypeError that we can redirect to a given page in the documentation."""

    pass

DistilabelNotImplementedError

基类: DistilabelError, NotImplementedError

我们可以重定向到文档中给定页面的 NotImplementedError。

src/distilabel/errors.py 中的源代码
class DistilabelNotImplementedError(DistilabelError, NotImplementedError):
    """NotImplementedError that we can redirect to a given page in the documentation."""

    pass