Skip to content

Troubleshooting

IDE Not Showing Autocomplete

Symptoms: - No autocomplete for config attributes - IDE doesn't recognize config structure

Solutions:

  1. Ensure the .pyi file exists next to your load_config.py
  2. Reload your IDE/editor window
  3. Check that your language server is running (VSCode: check Python extension)
  4. For PyCharm: File → Invalidate Caches → Restart

Config Object is Immutable

Error:

dataclasses.FrozenInstanceError: cannot assign to field 'host'

Cause: Config is frozen by default (immutable dataclass).

Solutions:

Option 1: Use mutate_config() helper (recommended)

from heracless import mutate_config

config = load_config()
new_config = mutate_config(config, "database.host", "new-host")

Option 2: Load with frozen=False (not recommended for production)

config = load_config(frozen=False)
config.database.host = "new-host"


YAML Parsing Errors

Error:

heracless.utils.exceptions.YamlSyntaxError: Syntax Error in your YAML File:
 mapping values are not allowed in this context (line 3, column 8)

Cause: Invalid YAML syntax in config file. The message includes the line and column of the problem.

Solution: Validate your YAML:

heracless config.yaml --dry

Common issues: - Incorrect indentation - Missing colons - Invalid characters - Mixing tabs and spaces

YamlSyntaxError is also raised for YAML that heracless doesn't support: - More than one document in a file (separated by ---) - Custom or unsupported tags such as !!python/object or !!binary - Nesting deeper than 128 levels, or aliases expanding to more than 1,000,000 nodes


ConfigError

Error:

heracless.utils.exceptions.ConfigError: the top level of a config file must be a mapping of keys to values, found a sequence

Cause: The top level of the YAML file is a list or a single value instead of a mapping.

Solution: Put your settings under keys at the top level of the file.


Config Is None

Cause: The config file is empty or only contains comments. load_config() returns None in that case and no stub is written.

Solution: Add your settings to the file.


DirectoryError / FileNotFoundError

Error:

heracless.utils.exceptions.DirectoryError: The given Directory or Path: config.yaml is not existing

Cause: The config file doesn't exist, or the directory the stub should be written to doesn't exist. DirectoryError is a subclass of FileNotFoundError, so except FileNotFoundError catches it too. Heracless does not create a missing config file.

Solutions:

  1. Check the path in CONFIG_YAML_PATH is correct
  2. Use absolute paths or Path(__file__) for relative paths:
    CONFIG_YAML_PATH = Path(__file__).parent / "config.yaml"
    
  3. Verify the config file exists:
    ls -la config.yaml
    

Type Checking Not Working

Symptoms: - mypy doesn't catch config typos - No type errors for invalid attribute access

Solutions:

  1. Ensure .pyi stub file is generated (set stub_dump=True)
  2. Run mypy with correct configuration:
    mypy --strict src/
    
  3. Check mypy is using the correct Python version:
    mypy --version
    

Stub File Not Generated

Cause: stub_dump=False or file_path=None

Solution:

def load_config(..., stub_dump: bool = True) -> Config:
    file_path = Path(__file__).resolve() if stub_dump else None
    return _load_config(config_path, file_path, frozen=frozen)

Ensure stub_dump=True (default).


Still Having Issues?

If you encounter other problems:

  1. Check the GitHub Issues
  2. Open a new issue with:
  3. Heracless version (pip show heracless)
  4. Python version
  5. Operating system
  6. Minimal reproducible example
  7. Expected vs actual behavior