{"record":{"id":"b971633f0f0c568d","repo":"invoke-ai/InvokeAI","slug":"failed-to-load-config-file-config-path-e","errorCode":null,"errorMessage":"Failed to load config file {config_path}: {e}","messagePattern":"Failed to load config file (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"invokeai/app/services/config/config_default.py","lineNumber":636,"sourceCode":"    if migrated:\n        shutil.copy(config_path, config_path.with_suffix(\".yaml.bak\"))\n        try:\n            # load and write without environment variables\n            migrated_config = DefaultInvokeAIAppConfig.model_validate(loaded_config_dict)\n            migrated_config.write_file(config_path)\n        except Exception as e:\n            shutil.copy(config_path.with_suffix(\".yaml.bak\"), config_path)\n            raise RuntimeError(f\"Failed to load and migrate v3 config file {config_path}: {e}\") from e\n\n    try:\n        # Meta is not included in the model fields, so we need to validate it separately\n        config = InvokeAIAppConfig.model_validate(loaded_config_dict)\n        assert config.schema_version == CONFIG_SCHEMA_VERSION, (\n            f\"Invalid schema version, expected {CONFIG_SCHEMA_VERSION}: {config.schema_version}\"\n        )\n        return config\n    except Exception as e:\n        raise RuntimeError(f\"Failed to load config file {config_path}: {e}\") from e\n\n\ndef load_external_api_keys(api_keys_file_path: Path) -> dict[str, str]:\n    \"\"\"Load external provider config (API keys and base URLs) from a dedicated YAML file.\"\"\"\n    if not api_keys_file_path.exists():\n        return {}\n\n    with open(api_keys_file_path, \"rt\", encoding=locale.getpreferredencoding()) as file:\n        loaded_api_keys: Any = yaml.safe_load(file)\n\n    if loaded_api_keys is None:\n        return {}\n\n    if not isinstance(loaded_api_keys, dict):\n        raise RuntimeError(f\"Failed to load api keys file {api_keys_file_path}: expected a mapping\")\n\n    parsed_api_keys: dict[str, str] = {}\n    for field_name in EXTERNAL_PROVIDER_CONFIG_FIELDS:","sourceCodeStart":618,"sourceCodeEnd":654,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/config/config_default.py#L618-L654","documentation":"load_and_migrate_config wraps any failure while reading, parsing, validating, or schema-migrating the InvokeAI YAML config file (or validating the resulting InvokeAIAppConfig model, including schema-version mismatch) in a RuntimeError. It is a catch-all so callers get one consistent error naming the offending config_path. The original cause is chained via `from e`.","triggerScenarios":"Calling load_and_migrate_config(conf_path, ...) when the file does not exist or is unreadable, contains invalid YAML, fails pydantic validation against InvokeAIAppConfig, or asserts schema_version != CONFIG_SCHEMA_VERSION.","commonSituations":"Hand-edited invokeai.yaml with a typo or wrong type (e.g. string where int expected), stale config from an older InvokeAI version whose schema_version is below CONFIG_SCHEMA_VERSION, malformed env-var interpolation, or a corrupted/empty config file.","solutions":["Read the chained cause message to see whether the problem is YAML syntax, pydantic field validation, or schema version","Fix the YAML syntax or field type at the path/line reported in the cause","If schema_version is stale, back up invokeai.yaml and let the migration run (or manually migrate fields to the current schema)","If irrecoverable, delete or rename the config file and let InvokeAI regenerate defaults, then re-apply settings"],"exampleFix":"// before (invokeai.yaml)\ngeneration:\n  threads: \"four\"\n// after\n\ngeneration:\n  threads: 4","handlingStrategy":"try-catch","validationCode":"from pathlib import Path\nimport yaml\ndef config_file_ok(p: str) -> bool:\n    f = Path(p)\n    if not f.is_file():\n        return False\n    try:\n        data = yaml.safe_load(f.read_text())\n        return isinstance(data, dict)\n    except yaml.YAMLError:\n        return False","typeGuard":"def is_valid_config(data: object) -> bool:\n    return isinstance(data, dict) and isinstance(data.get(\"schema_version\", 0), int)","tryCatchPattern":"try:\n    config = load_and_migrate_config(conf_path)\nexcept RuntimeError as e:\n    logger.error(f\"config load failed: {e.__cause__}\")\n    raise SystemExit(1)","preventionTips":["Validate invokeai.yaml with yaml.safe_load after every manual edit","Keep schema_version in sync when upgrading InvokeAI; read release migration notes","Back up the config file before upgrades","Prefer env vars/CLI over hand-editing complex nested YAML"],"tags":["config","yaml","pydantic","startup"],"backgroundTag":"config-file-invalid","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}