oraios/serena · error · ValueError

Invalid line_ending: {value!r}. Valid values are: {valid}

Error message

Invalid line_ending: {value!r}. Valid values are: {valid}

What it means

LineEnding.from_str() converts a configured string into the LineEnding enum using cls(value.lower()). This ValueError is raised when the value is not one of the enum's accepted strings (e.g. 'lf', 'crlf', 'auto' style values), with the original parse error chained as __cause__.

Source

Thrown at src/serena/config/serena_config.py:272

    def newline_str(self) -> str | None:
        """The newline parameter value for :func:`open` and :meth:`Path.write_text`.

        Returns ``None`` for native mode (platform default).
        """
        if self is LineEnding.LF:
            return "\n"
        elif self is LineEnding.CRLF:
            return "\r\n"
        return None

    @classmethod
    def from_str(cls, value: str) -> "LineEnding":
        """Parse a string value into a :class:`LineEnding`."""
        try:
            return cls(value.lower())
        except ValueError as e:
            valid = [le.value for le in cls]
            raise ValueError(f"Invalid line_ending: {value!r}. Valid values are: {valid}") from e


@dataclass
class SharedConfig(ToolInclusionDefinition, ToStringMixin):
    """Shared between SerenaConfig and ProjectConfig, the latter used to override values in the form
    (same as in ModeSelectionDefinition).
    The defaults here shall be none and should be set to the global default values in SerenaConfig.
    """

    symbol_info_budget: float | None = None
    language_backend: LanguageBackend | None = None
    line_ending: LineEnding | None = None
    read_only_memory_patterns: list[str] = field(default_factory=list)
    ignored_memory_patterns: list[str] = field(default_factory=list)
    ls_specific_settings: dict = field(default_factory=dict)
    """Advanced configuration option allowing to configure language server implementation specific options, see SolidLSPSettings for more info."""

View on GitHub (pinned to 7fcbca7e62)

Solutions

  1. Set line_ending to one of the valid values listed in the error message (the enum's .value list).
  2. Avoid using raw escape sequences like '\r\n'; use the named enum value instead.
  3. Trim whitespace/quotes around the value in YAML.
  4. Check the LineEnding enum definition in src/serena/config/serena_config.py for the canonical list.

Example fix

# before (serena_config.yml)
line_ending: '\r\n'
# after
line_ending: crlf
Defensive patterns

Strategy: validation

Validate before calling

from serena.config.serena_config import LineEnding

VALID_ENDINGS = [le.value for le in LineEnding]

def validate_line_ending(value: str) -> None:
    if value.strip().lower() not in [v.lower() for v in VALID_ENDINGS]:
        raise ValueError(f"line_ending must be one of {VALID_ENDINGS}, got {value!r}")

Type guard

def is_valid_line_ending(value: str) -> bool:
    try:
        LineEnding(value.lower())
        return True
    except ValueError:
        return False

Try / catch

try:
    line_ending = LineEnding.from_str(cfg.get("line_ending", "auto"))
except ValueError as e:
    log.warning("%s; using default", e)
    line_ending = LineEnding.AUTO

Prevention

When it happens

Trigger: Setting line_ending to an unrecognized string in serena_config.yml or a project config, parsed via _from_dict/from_config_file; also calling LineEnding.from_str() directly with a bad value.

Common situations: Typos like 'LF\r', 'windows', 'unix', or '\r\n' (raw escape characters) instead of the enum's named values; hand-editing YAML without knowing the accepted vocabulary.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of oraios/serena@7fcbca7e62 (2026-08-29). Data as JSON: /api/errors/56f858c99b5d8774. Report an issue: GitHub.