{"record":{"id":"b4f46aff88ffbb71","repo":"invoke-ai/InvokeAI","slug":"invalid-regex-e","errorCode":null,"errorMessage":"Invalid regex: {e}","messagePattern":"Invalid regex: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/services/config/config_default.py","lineNumber":62,"sourceCode":"    \"external_openai_api_key\",\n    \"external_openai_base_url\",\n    \"external_seedream_api_key\",\n    \"external_seedream_base_url\",\n)\n\n\nclass URLRegexTokenPair(BaseModel):\n    url_regex: str = Field(description=\"Regular expression to match against the URL\")\n    token: str = Field(description=\"Token to use when the URL matches the regex\")\n\n    @field_validator(\"url_regex\")\n    @classmethod\n    def validate_url_regex(cls, v: str) -> str:\n        \"\"\"Validate that the value is a valid regex.\"\"\"\n        try:\n            re.compile(v)\n        except re.error as e:\n            raise ValueError(f\"Invalid regex: {e}\")\n        return v\n\n\nclass InvokeAIAppConfig(BaseSettings):\n    \"\"\"Invoke's global app configuration.\n\n    Typically, you won't need to interact with this class directly. Instead, use the `get_config` function from `invokeai.app.services.config` to get a singleton config object.\n\n    Attributes:\n        host: IP address to bind to. Use `0.0.0.0` to serve to your local network.\n        port: Port to bind to.\n        allow_origins: Allowed CORS origins.\n        allow_credentials: Allow CORS credentials.\n        allow_methods: Methods allowed for CORS.\n        allow_headers: Headers allowed for CORS.\n        ssl_certfile: SSL certificate file for HTTPS. See https://www.uvicorn.dev/settings/#https.\n        ssl_keyfile: SSL key file for HTTPS. See https://www.uvicorn.dev/settings/#https.\n        log_tokenization: Enable logging of parsed prompt tokens.","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/config/config_default.py#L44-L80","documentation":"validate_url_regex is a pydantic field validator that compiles the configured URL-filter regex with re.compile(); if re.error is raised the ValueError 'Invalid regex: {e}' surfaces. This guarantees the app never stores an un-compilable regex used for URL filtering.","triggerScenarios":"Setting the url_regex config field (env var, config file, or CLI) to a syntactically invalid regex such as 'foo(' , '[unclosed' , or '*quantifier'.","commonSituations":"Hand-edited invokeai.yaml with an escaping mistake (e.g. '\\.' vs '.') ; quoting issues where backslashes are eaten by YAML/env parsing; porting a JavaScript regex with unsupported syntax into Python.","solutions":["Fix the regex syntax reported in the message (e.g. close the group, escape the bracket)","Validate the pattern quickly in Python: re.compile(your_pattern) before putting it in config","Prefer raw strings in YAML/ENV to preserve backslashes (use single quotes in YAML)"],"exampleFix":"// before (invokeai.yaml)\nurl_regex: '.*\\.(png|jpg'   # unclosed group\n// after\nurl_regex: '.*\\.(png|jpg)$'","handlingStrategy":"validation","validationCode":"import re\ntry:\n    re.compile(cfg.url_regex)\nexcept re.error as e:\n    raise ValueError(f\"fix url_regex in config: {e}\")","typeGuard":null,"tryCatchPattern":"try:\n    InvokeAIAppConfig(url_regex=pattern)\nexcept ValueError as e:\n    if str(e).startswith('Invalid regex'):\n        print('Fix the regex in invokeai.yaml:', e)","preventionTips":["Test regexes with re.compile before adding to config","Use YAML single quotes to preserve backslashes","Avoid porting JS-specific regex syntax into Python"],"tags":["config","validation","regex","pydantic"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}