{"record":{"id":"02b2ef8a5e8b8d61","repo":"NanmiCoder/MediaCrawler","slug":"xhsstorefactory-create-store-invalid-save-option","errorCode":null,"errorMessage":"[XhsStoreFactory.create_store] Invalid save option only supported csv or db or json or sqlite or mongodb or excel ...","messagePattern":"\\[XhsStoreFactory\\.create_store\\] Invalid save option only supported csv or db or json or sqlite or mongodb or excel \\.\\.\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"store/xhs/__init__.py","lineNumber":50,"sourceCode":"\n\nclass XhsStoreFactory:\n    STORES = {\n        \"csv\": XhsCsvStoreImplement,\n        \"db\": XhsDbStoreImplement,\n        \"postgres\": XhsDbStoreImplement,\n        \"json\": XhsJsonStoreImplement,\n        \"jsonl\": XhsJsonlStoreImplement,\n        \"sqlite\": XhsSqliteStoreImplement,\n        \"mongodb\": XhsMongoStoreImplement,\n        \"excel\": XhsExcelStoreImplement,\n    }\n\n    @staticmethod\n    def create_store() -> AbstractStore:\n        store_class = XhsStoreFactory.STORES.get(config.SAVE_DATA_OPTION)\n        if not store_class:\n            raise ValueError(\"[XhsStoreFactory.create_store] Invalid save option only supported csv or db or json or sqlite or mongodb or excel ...\")\n        return store_class()\n\n\ndef get_video_url_arr(note_item: Dict) -> List:\n    \"\"\"\n    Get video url array\n    Args:\n        note_item:\n\n    Returns:\n\n    \"\"\"\n    if note_item.get('type') != 'video':\n        return []\n\n    video_dict = note_item.get('video')\n    if not video_dict:\n        return []","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/NanmiCoder/MediaCrawler/blob/d6f7c5bb906b6dac40ddf343ef9e26438a3de092/store/xhs/__init__.py#L32-L68","documentation":"Raised by XhsStoreFactory.create_store() when config.SAVE_DATA_OPTION is not a key in the xhs STORES registry (csv, db, postgres, json, jsonl, sqlite, mongodb, excel). Fail-fast at first store creation during a xiaohongshu crawl.","triggerScenarios":"SAVE_DATA_OPTION set to an unregistered value — typo, wrong case ('Excel'), or a backend name from other tooling — when the xhs crawler calls create_store() to persist notes/comments.","commonSituations":"Most common first-run failure for xhs users who edited config/base_config.py; switching from json to a database without knowing the exact key; env var override with a different value than the file.","solutions":["Set SAVE_DATA_OPTION to exactly: csv, db, postgres, json, jsonl, sqlite, mongodb, or excel","'json' is the default and needs no external services — start there for a first run","If you intended MySQL, the key is 'db' plus the MySQL env/connection config","Double-check no env var (SAVE_DATA_OPTION) overrides the file value"],"exampleFix":"// before\nSAVE_DATA_OPTION = \"mongo\"\n\n// after\nSAVE_DATA_OPTION = \"mongodb\"","handlingStrategy":"validation","validationCode":"from store.xhs import XhsStoreFactory\n\nif config.SAVE_DATA_OPTION not in XhsStoreFactory.STORES:\n    raise SystemExit(\n        f\"SAVE_DATA_OPTION={config.SAVE_DATA_OPTION!r} invalid; \"\n        f\"choose from {sorted(XhsStoreFactory.STORES)}\"\n    )","typeGuard":"def is_valid_save_option(opt: str) -> bool:\n    return isinstance(opt, str) and opt in XhsStoreFactory.STORES","tryCatchPattern":"try:\n    store = XhsStoreFactory.create_store()\nexcept ValueError as e:\n    raise SystemExit(f\"fix config before crawling: {e}\") from e","preventionTips":["'mongodb' not 'mongo'; 'excel' not 'xlsx' — use the registry keys verbatim","Check env overrides for SAVE_DATA_OPTION","Validate before launching long crawls"],"tags":["configuration","storage","xhs","xiaohongshu","startup"],"backgroundTag":null,"analyzedSha":"d6f7c5bb906b6dac40ddf343ef9e26438a3de092","analyzedAt":"2026-08-15T01:39:07.505Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}