Skip to content

omop-config init fails when OA_CONFIG_PATH points at a non-existent file #36

Description

@nicoloesch

Summary

_resolve_config_path() raises FileNotFoundError at import time whenever OA_CONFIG_PATH is set to a path that doesn't exist yet. This defeats the entire purpose of init, which is supposed to create that file.

Reproduction

export OA_CONFIG_PATH=/tmp/scratch/config.toml
omop-config init

Actual behaviour

Crashes immediately with FileNotFoundError, before init's own command logic gets a chance to run at all. Root cause is in loader.py:

def _resolve_config_path() -> Path:
    raw = os.environ.get(ENV_CONFIG_PATH)
    if raw:
        p = _normalize_path(raw)
        if not p.exists():
            raise FileNotFoundError(f"{ENV_CONFIG_PATH} points to a non-existent file: {raw!r}")
        ...
        return p
    return DEFAULT_CONFIG_PATH


CONFIG_PATH: Path = _resolve_config_path()  # runs at module import

The existence check only applies on the explicit-OA_CONFIG_PATH branch. The default-path branch skips it entirely, and init there happily creates both the file and its parent directories.

Expected behaviour

omop-config init should create the file (and parent directories) at OA_CONFIG_PATH the same way it does for the default path. The existence check shouldn't apply before init has had a chance to run.

Error output

Traceback (most recent call last):
  File "/home/vscode/venv/bin/omop-config", line 4, in <module>
    from oa_configurator.cli import app
  File "/workspace/OA_Configurator/src/oa_configurator/__init__.py", line 20, in <module>
    from .io import ConfigSaveError, FLAT_ENV_PATH, save_stack_config, write_env_file
  File "/workspace/OA_Configurator/src/oa_configurator/io.py", line 14, in <module>
    from .loader import CONFIG_PATH, _normalize_path, invalidate_cache
  File "/workspace/OA_Configurator/src/oa_configurator/loader.py", line 86, in <module>
    CONFIG_PATH: Path = _resolve_config_path()
                        ^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/OA_Configurator/src/oa_configurator/loader.py", line 77, in _resolve_config_path
    raise FileNotFoundError(f"{ENV_CONFIG_PATH} points to a non-existent file: {raw!r}")
FileNotFoundError: OA_CONFIG_PATH points to a non-existent file: '/tmp/scratch/config.toml'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions