Skip to content

Handle ValueError while reading configuration files by configparser #122454

Closed as not planned
@picnixz

Description

@picnixz

Bug report

Bug description:

In configparser.RawConfigParser.read, when open() raises OSError, the file is skipped. Note that the OSError guard also includes the parsing phase and not just the call to open().

However, open() can raise a ValueError in the following cases:

  • On Linux: The file has embedded NUL bytes.
  • On Linux: The file has surrogate codes. On Windows, this raises an OSError instead.

Note that there is a test for checking when a file cannot be read assuming it has been opened. In particular, to retain compatibility, we should only skip the file if we cannot open it in the first place. Any issue during the parsing (such as an encoding or decoding error) should be propagated (but an OSError during the parsing should be suppressed as it is currently the case).

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions