config2py.errors#

Error classes for config2py.

Functions

report_missing_config_file(path, *[, ...])

Act on a config source path that is not an existing, readable file.

unusable_config_file_problem(path)

Why path can't be read as a config file, as (error_class, errno, reason), or None if it is an existing, readable, non-folder path.

validate_on_missing(on_missing, *[, name])

Check that on_missing is one of ON_MISSING_OPTIONS and return it.

Exceptions

Config2PyError

Base class for config2py errors.

Config2PyWarning

Warnings issued by config2py (e.g. permissions it could not tighten).

ConfigNotFound

Raised when a config file is not found.

InsecureConfigFolderWarning

A folder used to store config values (which may be secrets) is owned by another user or writable by others, who could plant a symlink or file there to redirect or read those values (see i2mint/config2py#45).

MissingConfigFileWarning

A path given as a config source is not an existing, readable file (it is missing, a folder, or unreadable), so it was read as empty (see i2mint/config2py#27 and /43).

UserInputUnavailable

Raised when a value would be asked of the user but nobody can answer: stdin is closed, at end of file, or unreadable (cron, CI, a subprocess, pytest's output capture).

exception config2py.errors.Config2PyError[source]#

Bases: Exception

Base class for config2py errors.

exception config2py.errors.Config2PyWarning[source]#

Bases: UserWarning

Warnings issued by config2py (e.g. permissions it could not tighten).

exception config2py.errors.ConfigNotFound[source]#

Bases: Config2PyError

Raised when a config file is not found.

exception config2py.errors.InsecureConfigFolderWarning[source]#

Bases: Config2PyWarning

A folder used to store config values (which may be secrets) is owned by another user or writable by others, who could plant a symlink or file there to redirect or read those values (see i2mint/config2py#45).

exception config2py.errors.MissingConfigFileWarning[source]#

Bases: Config2PyWarning

A path given as a config source is not an existing, readable file (it is missing, a folder, or unreadable), so it was read as empty (see i2mint/config2py#27 and /43).

exception config2py.errors.UserInputUnavailable[source]#

Bases: ConfigNotFound

Raised when a value would be asked of the user but nobody can answer: stdin is closed, at end of file, or unreadable (cron, CI, a subprocess, pytest’s output capture). A ConfigNotFound, so get_config moves on to its next source or returns its default (see i2mint/config2py#83).

config2py.errors.report_missing_config_file(path, *, on_missing='warn', stacklevel=2, resolved_path=None)[source]#

Act on a config source path that is not an existing, readable file.

The problem is told apart: missing, a directory, or unreadable (permission denied). A path that exists, is readable and isn’t a folder (a device or a pipe) is reported as not a regular file.

Parameters:
  • on_missing (str) – "warn" issues a MissingConfigFileWarning, "raise" raises FileNotFoundError (IsADirectoryError for a folder, PermissionError for an unreadable file), "ignore" does nothing.

  • stacklevel (int) – Passed to warnings.warn, so the warning points at the caller’s code (2 is the caller of this function).

  • resolved_path (str | PathLike | None) – What path resolves to (~ expanded, …), when that is what was actually looked at. path is what the messages show.

Return type:

None

config2py.errors.unusable_config_file_problem(path)[source]#

Why path can’t be read as a config file, as (error_class, errno, reason), or None if it is an existing, readable, non-folder path.

Return type:

tuple[type[OSError], int, str] | None

config2py.errors.validate_on_missing(on_missing, *, name='on_missing')[source]#

Check that on_missing is one of ON_MISSING_OPTIONS and return it.

name is the argument the error message names (on_unsafe_folder uses the same three options).

Return type:

str