{"record":{"id":"93a0f3e75772dc40","repo":"FoundationAgents/MetaGPT","slug":"error-reading-file-file-name-str-e","errorCode":null,"errorMessage":"Error reading file '{FILE_NAME}': {str(e)}","messagePattern":"Error reading file '(.+?)': (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"metagpt/ext/spo/utils/load.py","lineNumber":28,"sourceCode":"def set_file_name(name: str):\n    global FILE_NAME\n    FILE_NAME = name\n\n\ndef load_meta_data(k: int = SAMPLE_K):\n    # load yaml file\n    config_path = Path(__file__).parent.parent / \"settings\" / FILE_NAME\n\n    if not config_path.exists():\n        raise FileNotFoundError(f\"Configuration file '{FILE_NAME}' not found in settings directory\")\n\n    try:\n        with config_path.open(\"r\", encoding=\"utf-8\") as file:\n            data = yaml.safe_load(file)\n    except yaml.YAMLError as e:\n        raise ValueError(f\"Error parsing YAML file '{FILE_NAME}': {str(e)}\")\n    except Exception as e:\n        raise Exception(f\"Error reading file '{FILE_NAME}': {str(e)}\")\n\n    qa = []\n\n    for item in data[\"qa\"]:\n        question = item[\"question\"]\n        answer = item[\"answer\"]\n        qa.append({\"question\": question, \"answer\": answer})\n\n    prompt = data[\"prompt\"]\n    requirements = data[\"requirements\"]\n    count = data[\"count\"]\n\n    if isinstance(count, int):\n        count = f\", within {count} words\"\n    else:\n        count = \"\"\n\n    random_qa = random.sample(qa, min(k, len(qa)))","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/ext/spo/utils/load.py#L10-L46","documentation":"A generic wrapper raised when opening or reading the SPO settings yaml fails for a non-YAMLError reason — typically PermissionError, IsADirectoryError, or UnicodeDecodeError from config_path.open(). The original exception text is embedded and is the real clue.","triggerScenarios":"FILE_NAME set to a directory name instead of a file; insufficient file permissions (e.g. file created by root, read by another user); file saved in a non-UTF-8 encoding so encoding='utf-8' decoding fails.","commonSituations":"Settings files created under Docker/root and mounted read-only or with restrictive modes; editors saving UTF-16 or with BOM issues; FILE_NAME accidentally including a path separator resolving to a directory.","solutions":["Check the embedded exception text to identify PermissionError vs UnicodeDecodeError vs IsADirectoryError.","chmod/chown the settings file so the running user can read it; keep extensions plain (no directories) in set_file_name.","Re-save the yaml as UTF-8 without BOM."],"exampleFix":"# before: file saved as UTF-16 by an editor\n# after: re-encode\n# iconv -f UTF-16 -t UTF-8 settings/my.yaml > settings/my.yaml.utf8 && mv settings/my.yaml.utf8 settings/my.yaml","handlingStrategy":"try-catch","validationCode":"import os, pathlib\n\ndef readable_utf8(p: str) -> bool:\n    path = pathlib.Path(p)\n    if not path.is_file() or not os.access(path, os.R_OK):\n        return False\n    try:\n        path.read_text(encoding=\"utf-8\")\n        return True\n    except UnicodeDecodeError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    data = load_meta_data()\nexcept Exception as e:\n    if \"Error reading file\" in str(e):\n        logger.error(\"settings file unreadable (permissions/encoding): %s\", e)\n    raise","preventionTips":["Standardize UTF-8 no-BOM in editor settings for yaml files.","Check file permissions when sharing settings files across containers/users."],"tags":["file-io","permissions","encoding","spo"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}