Skip to content

Add LettuceDetectError, its three subclasses and the result warning #138

Closed

Description

@hslev

Parent: #137 · Epic: #126 · Blocked by: #133, and the decision elsewhere on where shared types and error classes live
Work on branch 137-build-detect-requests-and-read-typed-results-and-errors; commit the changes and close the ticket.

Problem

Every failure today is a ValueError, a provider exception, or a logged error that returns no spans (base.py:65-72, llm.py:109, llm.py:123, llm.py:424). Callers cannot handle failures by class or by stable code, and a degraded result has no place to say so.

Current behavior

  • lettucedetect/detectors/base.py:65 _validate_min_confidence raises a bare ValueError.
  • lettucedetect/detectors/llm.py:109 and :123 raise ValueError for an unknown language and for native with judge-only options.
  • No error classes or warning model exist in the package.

Steps

  1. Implement a base class LettuceDetectError(Exception) where the shared-types decision puts the error classes. It holds the stable snake_case code and the message, so a caller can catch every library error with one except LettuceDetectError and read .code.
  2. Implement three subclasses of LettuceDetectError: InvalidInputError (an argument of a call; also has param), ConfigurationError (a constructor argument, a setting or a missing package; param optional), UpstreamError (a failed or missing reply from a service). Whether they also subclass ValueError follows the decision. If they do, LettuceDetectError stays the common base.
  3. Implement the result warning model with a stable code; other fields follow the decision.
  4. An error built from a request never puts customer text in its message (refer to items by position). Chain foreign errors with raise ... from; the base class keeps __cause__ intact.
  5. Export LettuceDetectError and the three subclasses from lettucedetect.detectors.

Acceptance criteria

  • LettuceDetectError exists with a code; InvalidInputError, ConfigurationError and UpstreamError are subclasses of it, so except LettuceDetectError catches all three.
  • Every error has code, InvalidInputError has param; a test checks code and param are readable as attributes and that __cause__ is kept when chained.
  • A test builds an error from a request containing a known answer and asserts the message does not contain it.
  • The warning model has a code; importable from lettucedetect.detectors.
  • No detector changes; existing tests pass; follows CONTRIBUTING "Errors and logging".

Start here

uv run --extra dev pytest tests -q -x

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agent

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions